Note Two - data member. • If a function of a class is...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Note Two Object can be passed to a function by value or by reference. // Call by value ReturnedDAtaType FunctionName(ClassName ObjectName) // Call by Reference ReturnedDAtaType FunctionName(ClassName & ObjectName) To prevent changing any data when call by reference either function itself declared as constant function ReturnedDAtaType FunctionName(ClassName & ObjectName) const Or constant parameter ReturnedDAtaType FunctionName(ClassName const & ObjectName) Any non-member function can use access all class member (data or function) if it is declared as a friend function in a class definition. To declare a friend function you have to write this statement in any part in class definition friend FunctionProtoType; Also a class can be declared as a friend class so all its function can access the member of the other class, and to declare a class as a friend class we have to write the following statement in any place in class definition friend class ClassName; Any data member or member function can be declared as a static function or static
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: data member. • If a function of a class is static, in the class definition it is declared using the keyword static in its heading. • If a data member of a class is static, it is declared using the keyword static. • A static member function or data of a class can be accessed either by the object name or by using the class name and the scope resolution operator (if the member is public). ClassName::StaticVariableName; ClassName::StaticFunctionName( ); 1 • Static data member (private or public) initialized as follows(usually at file scope): DataType ClassName::StaticVariableName = InitialValue; • In the definition of a static member function, you cannot use non-static data member or a non-static function unless there is an object declared locally that accesses the non-static data member or the non-static member function. • Every object of a class maintains a hidden pointer to itself, and the name of this pointer is this. • Static member function has no this pointer. 2...
View Full Document

This note was uploaded on 03/15/2010 for the course STATISTIC 472 taught by Professor Amjad during the Spring '08 term at Yarmouk University.

Page1 / 2

Note Two - data member. • If a function of a class is...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online