Page 81 - DCAP404 _Object Oriented Programming
P. 81
Object-oriented Programming
Notes The following program segment shows how a member function is declared outside the class
declaration.
class sample
{
private:
int x;
int y;
public:
int sum (); // member function declaration
};
int sample:: sum ( ) //member function definition
{
return (x+y);
}
Notes Please note the use of the scope operator double colon (::) is important for defining
the member functions outside the class declaration.
Let us consider the following program snippet:
class first
{
private:
int x;
inty;
public :
int sum();
};
class second
{
private:
intx;
int y;
public:
int sum();
};
first one;
74 LOVELY PROFESSIONAL UNIVERSITY