944,153 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1548
  • C++ RSS
Oct 17th, 2005
0

C++

Expand Post »
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manishgurnaney is offline Offline
1 posts
since Oct 2005
Oct 17th, 2005
0

Re: C++

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:

C++ Syntax (Toggle Plain Text)
  1. class Something {
  2. private:
  3. Something();
  4.  
  5. static list<Something *> somethings;
  6. public:
  7. static Something *New() {
  8. Something *something = new Something;
  9. somethings.push_back(something);
  10. return something;
  11. }
  12. //...
  13. };
  14.  
  15. // ...
  16. // In code somewhere
  17.  
  18. 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
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005
Oct 17th, 2005
0

Re: C++

>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?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help!!!!!!
Next Thread in C++ Forum Timeline: Concordance, Linked Lists and classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC