Let me tell you why you are here. You have come because you know something. What you know
you can't explain but you feel it. You've felt it
your whole life, felt that something is wrong with
the world. You don't know what, but it's there like
a splinter in your mind, driving you mad. It is
this feeling that brought you to me. Do you know
what I'm talking about?
12/11/2007
A sealed class in C++
I want a 'sealed' class in native C++ just like 'sealed' in C++/CLI and C# or 'final' in Java. I googled it then got following solution.
template<typename T> class DeriveLock { private:
DeriveLock() {} ~DeriveLock() {} friend T;
};
class SealedClass : virtual public DeriveLock<SealedClass> { };
Well, template friends is a non-standard C++. To get it working you have to implement different workarounds for different compilers. Some of them will not support it at all, unfortunately...
I wrote some article and code on this issue too, check it out - http://www.jetsnail.com/tech-blog/38-cpp/52-noninheritable
Well, template friends is a non-standard C++. To get it working you have to implement different workarounds for different compilers. Some of them will not support it at all, unfortunately...
ReplyDeleteI wrote some article and code on this issue too, check it out - http://www.jetsnail.com/tech-blog/38-cpp/52-noninheritable