"Saumya" <sa**********@y ahoo.com> wrote in message
news:e9******** *************** ***@posting.goo gle.com...
Not a very technical reason pal, but it just struck me while I was
learning Java and encountered the "final" keyword there.
U mean how to simulate final java class concept in c++.....here is
program.I guess its similar to creating singleton pattern
// Make ctor private so that class cannot be inheriated
//Use static member function to create object of its own which will return
ptr to same class obj
#include <iostream.h>
class X{
private :
int x;
X(); // private ctor
public :
static X* getMePrivateObj ect(); // this will help me creating handle rather
for normal object
};
X::X(){
cout<<"in constructor"<<e ndl;
x=0;
};
X* X::getMePrivate Object(){
X *pMyP = new X();
return pMyP;
};
/*class Y : public X //cannot do this as X has private ctor
{
public:
Y(){}
void print(){ cout<<"Display me if u can";}
};
*/
void main(void){
X *pMyP = X::getMePrivate Object();
//Rest of ur code
}