#include <iostream.h>
#include<conio.h>
class sample
{
int a, b;
public:
sample(int, int);
sample() { }
void display() const; // 'const' member function prototype
~sample() { }
};
sample::sample(int x, int y)
{
a = x; b = y;
}
void sample::display() const // 'const' member function defined
{
cout << "a = " << a << "\t";
cout << "b = " << b << "\n";
}
void main(void)
{
clrscr();
const sample A(10,20); // 'const' Object declaration
A.display(); // 'const' object invoking 'const' member function
getch();
}
0 comments:
Post a Comment