class Unoverloadable;
class Base
{
private:
friend Unoverloadable;
Base(){}
};
class Unoverloadable : publicvirtual Base
{
// class definition
};
now since derived classes need access to their base class constructors, and only Unoverloadable can access Base as its constructor is private, nothing can be derived from Unoverloadable.
May I ask why exactly you want to prevent inheritance?
I know auto is coming (as Stroustrup intended way back in the mists of time when he started all this, apparently). I don't know if I'd call it interesting; I've never really minded having to declare a type when I create an object.
Although I haven't heard of a "final" keyword for C++, I would be really disappointed if it was implemented. That's a feature of Java that I really didn't like. Can't we point guns at our feet when we want to?
Doesn't have to be open source. Could be closed source with an interface for the library. Don't get me wrong I'm all for the current c++ philosophy and completely unrestricted code. Just playing the devils advocate here.
Where's my holy water? I need to sprinkle some on the seraph. ;)
I'm pretty sure Java has a keyword for creating interfaces separate from the implementations, but I haven't touched the language in so long I almost forgot.
auto... I already sorta made something like that: #define let(x,y) typeof(y) x=y
Also, if you don't want people to inherit, why not just do this: class Foo{//If you inherit, I'll hunt you down and eat your soul
(Using whatever threat you can get away with, obviously.)
@Albatross: It does. It's basically a class with only (pure?) virtual functions. Since Java doesn't support multiple inheritance it's the only way to do some things in it.
By the way, another theoretical question.
In Java, keyword ‘final’ also can prevent the redefining of method. Is there any trick in C++ to do the same?