четверг, 28 февраля 2013 г.

2. Understand how to use const and mutable

2. Понимать, как использовать const и mutable

const применяется в следующих случаях:

1. Создание неизменяемых переменных:
int a = 5;
const int b = 6;

a = 3; // правильно
b = 3; // ошибка

1. Know how to use basic types and cast between them

1. Знать основные типы данных, их использование и приведение

В языке C++ существуют следующие базовые типы данных:
  • int - целое число;
  • floatс плавающей точкой (вещественное число);
  • doubleс плавающей точкой двойной точности;
  • char - символьные данные (символ);
  • bool - логический тип (принимает значение true или false).
Для целочисленного типа существуют модификаторы доступа signed и unsignedМодификатор типа unsigned указывает, что переменная принимает только неотрицательные значения.
Приведем простой пример программы на С++, которая оперирует простыми типами данных и выводит их значения на экран:
#include <iostream>

using namespace std;

int main()
{
    int a;                   // целое число
    bool isTrueValue = true; // булево значение
    float f = 0.1;           // вещественное число
    char s = 's';            // символ 's'

    a = 5;

    cout << "a= " << a << endl
         << "isTrueValue= " << isTrueValue << endl
         << "f= " << f << endl
         << "s= " << s << endl;

    return 0;
}
В C++ различают явное и неявное преобразование типов данных. Неявное преобразование типов данных выполняет компилятор С++, явное преобразование данных выполняет разработчик. О приведении типов данных можно сказать следующее: «Результат любого вычисления будет преобразовываться к наиболее точному типу данных, из тех типов данных, которые участвуют в вычислении».
Следующий пример демонстрирует это:

#include <iostream>

using namespace std;

int main()
{
    int a = 7;                 
    int b = 2;
 
    float c = 7.0;
    float d = 2.0;

    cout << "(int/int) a/b = " << a/b << endl
         << "(float/float) c/d = " << c/d << endl
         << "(int/float) a/d = " << a/d << endl
         << "(float/int) c/b = " << c/b << endl;

    return 0;
}

Полезные ссылки:
  1. http://habrahabr.ru/post/106294/
  2. http://alenacpp.blogspot.com/2005/08/c.html
  3. http://www.cppreference.com
  4. http://www.cplusplus.com/doc/tutorial/typecasting/
  5. http://doc.qt.nokia.com/4.7/qobject.html#qobject_cast
  6. http://www2.research.att.com/~bs/bs_faq2.html
  7. http://doc.qt.nokia.com/4.7/qvariant.html#qvariant_cast
  8. http://www.rsdn.ru/Forum/Info/FAQ.cpp.c-stylecast.aspx

Подготовка к сдаче Core C++ for Qt Developers

Экзамен Qt Essentials успешно сдан, поэтому самое время начать подготовку к Qt Advanced Exam и в частности к Core C++ for Qt Developers.
После того, как Qt был выкуплен компанией Digia, информация полезная для подготовки к экзамену Qt Curriculum канула в Лету (это список экзаменационных тем и учебные материалы). Список в итоге удалось разыскать на просторах интернета. Вот он:

 Core C++ for Qt Developers Curriculum Block

Types, Declarations and Definitions
1) Know how to use basic types and cast between them
2) Understand how to use const and mutable
3) Understand the different scopes that identifiers have
4) Understand how to define functions and use argument lists
5) Understand how to define and use references
6) Understand how to manage object creation and destruction
7) Know how to define and use namespaces
8) Understand how to separate code into header files and source files

Classes
9) Understand member accessibility
10) Know constructors, how they are used and member initialization
11) Know how to write const methods const-correct classes
12) Understand static methods and static member initialization
13) Understand how objects are copied and assigned

Inheritance and Polymorphism
14) Know how constructors and destructors are used in derived classes
15) Understand how to use base class pointers
16) Non-public derivation of classes
17) Know virtual functions, how to define and use them
18) Understand why virtual destructors are needed
19) Know how to use abstract classes and implement pure virtual functions
20) Understand how functions and operators can be overloaded, overridden and hidden in derived classes
21) Understand issues that come up from multiple inheritance

Miscellaneous Topics
22) Understand how to use templates and Qt containers
23) Understand operator overloading
24) Know the explicit keyword and how conversion constructors are used

Этот пост является вступительным для серии постов о подготовке к экзамену Core C++ for Qt Developers. Каждый пост из серии будет содержать ответ на один из представленных выше вопросов. Таким образом всего будет 24 поста, посвященных ответам на вопросы экзамена. 

Планирую тратить в среднем по 2 дня на публикацию одного ответа. Итого через 1.5 месяца можно с чистой душой идти на сдачу. 

Поехали...