How Can i Create a final class in C++?
i have tried by making constructors private . but i want to know an efficient way of doing this?

A final class? You mean like a final variable in Java? I haven't heard of that before in C++. But to answer your question about making private constructors, the only reason why I could see you doing something like that would be in this case:

class Something {

	static list<Something *> somethings;
	static Something *New() {
		Something *something = new Something;
		return something;

//  ...
//  In code somewhere

Something *something = Something::New();

That way you could possibly do a kind of memory management..not sure how that ties in with a 'final' class, though.


>How Can i Create a final class in C++?
A "final" class in Java is a class that cannot be derived from, it's quite literally a concrete class that will never have subclasses. In C++ you basically can't do it without making the class harder to use. Are you doing this for the wrong reasons?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.