final class

K

Kai-Uwe Bux

Ganesh said:
Is there an equivalent of the "final class" of JAVA in C++?

a) not really. It's not really that much of a useful concept in C++.

b) Should you find yourself in a situation where you really really need it,
there is a way of faking it: you can prevent construction of objects of
derived classes as follows.

/*
This trick was found in news.lang.c++.moderated (Gennaro Prota)
see:
http://groups.google.com/group/comp...7136?lnk=gst&q=sealed&rnum=3#f63980680a2f7136
*/

class protected_constructor {
protected:

protected_constructor ( void ) {}

}; // protected_constructor


#define FINAL_CLASS private virtual protected_constructor


class X : FINAL_CLASS {};

class Y : public X {};

int main ( void ) {
Y y;
}



Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top