2. At the end of this tutorial you will be able to
• Write correct syntax of a class.
• Create data members and member functions of a class.
• Create objects of a class.
• Access the class members outside the class.
• Explain the memory representation of an object.
• Define functions inside and outside the class.
www.learnbywatch.com | yogendra@learnbywatch.com
3. Why create a class?
• class creates a user defined data type.
www.learnbywatch.com | yogendra@learnbywatch.com
4. General form of c++ class
www.learnbywatch.com | yogendra@learnbywatch.com
class class-name {
private data and functions
public:
public data and functions
};
5. Object Creation
www.learnbywatch.com | yogendra@learnbywatch.com
class class-name {
private data and functions
public:
public data and functions
};
class-name object-name;
class-name object1, object2;
6. Access class members
• The dot operator ( . )
• Required only if you are accessing a class member outside class.
www.learnbywatch.com | yogendra@learnbywatch.com
7. Define member function
www.learnbywatch.com | yogendra@learnbywatch.com
Inside class
return_type function_name(parameters)
{
function body
}
Outside class
return_type class_name::function_name(parameters)
{
function body
}
Scope resolution operator
8. Ask your questions
to learn better
Yogendra Pal
www.learnbywatch.com | yogendra@learnbywatch.com