In C++, during operator overloading, what are the conditions that affect the function from becoming a class member Vs being declared at the namespace level.
Answer:
* When an overloaded operator is a class member, the class member operator is only invoked when the operator is used with a left operand that is an object of class type. If the operator must obe used with a left operand of another type, then the overloaded operator must be a namespace member.
* The =, [], () and member access arrow "->", are required by the language to be defined as class member operators. ... and definition of any of these at namespace level will be a compile time error.
Reference : "Operator Overloading" C++ Primer Lippmann p.744
Difference between declaring a member function inside and outside the class
Difference between declaring a member function inside and outside the class..
Answer :
A member func defined inside the class in inline.( Reference : The Annotated C++ Reference Manual, section 9.3.2 p.188 )
Answer :
A member func defined inside the class in inline.( Reference : The Annotated C++ Reference Manual, section 9.3.2 p.188 )
Why Should static data members be defined outside the Class
Why Should static data members be defined outside the Class ?
Answer:
Because, static data members have external linkage, and do not belong to the class., similar to global members.( Reference : The Annotated C++ Reference Manual "Basic Concepts" p.28 )
Answer:
Because, static data members have external linkage, and do not belong to the class., similar to global members.( Reference : The Annotated C++ Reference Manual "Basic Concepts" p.28 )
Subscribe to:
Posts (Atom)