R-Value:
Remember prefix ++ return reference(L-Value), but postfix ++ return Type (R-value).
// i++ return an RValue, no identifiable memory address, cannot be increased any more.
i++ ++ ;//illegal
// ++i return a reference, a reference can be increased!
++ ++ i; // OK
A function call can return an LValue. prefix ++ is the best example in my view.
--------------------------------------------------------
new operator ==> new keyword, what we normally use to create an object
operator new ==> malloc
char *x = static_cast<char *>(operator new(100));
--------------------------------------------------------1. copy constructor ---> applied in situation when there is one existing object and you want to construct a new one based on that existing one
A_ a2=a1; // even if there is an assignment operator, it will call copy constructor!
2. assignment operator ---> as the name implies, the function of assignment operator is to assign, not construct. It is applied when there are two existing objects and you want to assign one to another
A_ a1, a2;
a1=a2;// assignment operator gets called!
3. Compiler will write constructor(default and copy) and assignment operator for you silently if you do not write it manually. You cannot define copy constructor only without defining default constructor, but you can define default constructor without defining copy constructor!
No comments:
Post a Comment