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 {
private:
	Something();

	static list<Something *> somethings;
public:
	static Something *New() {
		Something *something = new Something;
		somethings.push_back(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.

-Fredric

>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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.