2. Static member function - link
The differences between a static member function and non-static member functions are as follows.
- A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
- A static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
- A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
- A static member function cannot have access to the 'this' pointer of the class.
A smart pointer that deletes the instance it points to when going out of scope. It is supplied in the STL, in the header file memory.h.
4. Exception in destructor? - link
[17.3] How can I handle a destructor that fails?
Write a message to a log-file. Or call Aunt Tilda. But do not throw an exception!
5. Copy constructor is called when? - link
- Automatically called: A copy constructor is called in the following circumstances.
A x(y); // Where y is of type A.
f(x); // A copy constructor is called for value parameters.
x = g(); // A copy constructor is called for value returns.
6. Map
How to access the string?
for(mapType::const_iterator it = data.begin(); it != data.end(); ++it)
{
cout << "Who(key = first): " <<>first;
cout << " Score(value = second): " <<>second <<>
Not theMap[it] or theMap[i]
7. Prefix and postfix operator++() - link
class Date {
//...
public:
Date& operator++(); //prefix
Date& operator--(); //prefix
Date& operator++(int unused); //postfix
Date& operator--(int unused); //postfix
};
Postfix operators are declared with a dummy int argument (which is ignored) in order to distinguish them from the prefix operators, which take no arguments: 8. const member function - link
int capacity() const; // max size before reallocation
Member functions should be declared with the const keyword after them if they can operate on a const (this) object. If the function is not declared const, in can not be applied to a const object, and the compiler will give an error message. A const function can be applied to a non-const object
A function can only be declared const if it doesn't modify any of its fields.
** Note
This keyword can only be applied to non-static and non-const data members of a class. If a data member is declared mutable, then it is legal to assign a value to this data member from a const member function.
9. std:find(x, y, i) - link#include
iterator find( iterator start, iterator end, const TYPE& val );
The find() algorithm looks for an element matching val between start and end. If an element matching val is found, the return value is an iterator that points to that element. Otherwise, the return value is an iterator that points to end.
= bash or sh
(bsh is wrong!)
11. Access - link
We can summarize the different access types according to who can access them in the following way:
| Access | public | protected | private |
|---|---|---|---|
| members of the same class | yes | yes | yes |
| members of derived classes | yes | yes | no |
| not members | yes | no | no |
12. Pointer vs reference - link
No comments:
Post a Comment