In addition, to prevent inheritance, the actual constructor would have to be private, right?
Yes, as is implied by the page I linked. Anyway, it's static methods returning objects of your class.
I still find it a bit confusing, since even though there is no default constructor in the linked example, you can make a stack object. And if you can make a stack object using a (magic) default constructor like that, I don't see how that prevents inheritance.
I wonder if C++0x fixes this because otherwise inheritance in C++ is poorly conceived.
I can't talk about other systems, but making sure you don't have derived objects sure is a song and dance in C++. I just wish there were a keyword or something so it's completely clear what the intentions are of the person writing the class.
Sorry Elysia, you're 100% right, it seems you're experienced in this case.
Yes, it's expensive to do that, otherwise it will be complicated (creating your own programming language or creating sub-preproccessor just like Qt's moc).
I think I'll give up on this and just use only what I needed to solve things.
Thank you very much.
Stroustrup provides another "song and dance" solution that does not have such a limitation in his answer to the FAQ Can I stop people deriving from my class?.Quote:
Originally Posted by Sebastiani
Personally, unless documented otherwise, I stick to the rule that a class with no virtual functions should not be used as a base class. But yeah, having the rule enforced by a language feature would probably be good.