C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 1
Reputation: manishgurnaney is an unknown quantity at this point 
Solved Threads: 0
manishgurnaney manishgurnaney is offline Offline
Newbie Poster

C++

 
0
  #1
Oct 17th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 80
Reputation: Daishi is an unknown quantity at this point 
Solved Threads: 2
Daishi Daishi is offline Offline
Junior Poster in Training

Re: C++

 
0
  #2
Oct 17th, 2005
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++

 
0
  #3
Oct 17th, 2005
>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?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC