Defining a constructor/method outside the class -
For defining a constructor or method outside the class four things should be kept in mind -
- Return Type
- Class Name
- Scope Resolution Operator
- Constructor/Method name
Note - Constructors/Destructors don't have a return type, so while defining constructors/destructors outside the class return type is not specified.
Syntax - (return type) (class name)(scope
resolution operator)(constructor/method name)
For Example - Consider the definition of class student that a constructor, method and destructor.
class student
{
private :
int id ;
public :
student ( );
void add_student ( );
~student ( );
}
Implementing constructor student ( ) outside the class -
student : : student ( )
{
}
Implementing method add_student ( ) outside the class -
void student : : student ( )
{
}
Implementing destructor student ( ) outside the class -
student : : ~student ( )
{
}
No comments:
Post a Comment