TDDD38 Advanced Programming in C++, Computer exam 2013-03-26, Theory questions ------------------------------------------------------------------------------ 1. Static local object - The object has static storage duration (lifetime equal to the programs). Static class data member - The data member belongs to the class and not to every instance of the class. Static class member function - The function belongs to the class and not to every instance of the class. The member function can only access static member data. Static anonymous union - An anonymous union defines an unnamed object, see static objects above. Note: There are also a couple of deprecated cases, where anonymous namespaces is prefered. ------------------------------------------------------------------------------ 2. The special member functions are in C++98: default constructor, X(); used to default initialize new objects when no constructor arguments are given. copy constructor, X(const X&); used to initialize objects, e.g. in object declarations, value parameter passing, and value return from a function, by copying the content of the source to the destination. copy assignment operator, X& operator=(const X&); used to assign another object of the same type, by copying the content of the source to the destination. destructor, ~X(), if compiler generated. Used automatically when objects are to disappear. In C++11 also (not required this exam): move constructor, X(X&&); used to initialize objects, by moving content from source to destination. move assignment operator, X& operator=(X&&); used to move assign an object, by by moving the content from the source to the destination. These two will be used instead of the copy constructor/assignment in situations where the source object can be safely moved (typically a temporary, but also other objects which are to expire). ------------------------------------------------------------------------------ 3. Of any type, in principle, whether user defined (class, struct, enum, typedefined array) or primitive (int double, etc.), as long as it is a type for which the implementation of fun makes sence for T. The instantiation type must have copy/move defined (copy/move constructor, if a class type), since both the parameter and the return require this. ------------------------------------------------------------------------------ 4. SFINAE means, if a template instantiation fails, it is not a compile error, but instead discarded, which allows the compiler to continue. An error may occure, but first when all other possibilities are tried. ------------------------------------------------------------------------------ 5. The closest surrounding block in the dynamic call chain is the earliest resumption point, the latest is within the body of main. ------------------------------------------------------------------------------