0

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?

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Narue
0

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

0

>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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.