Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Shannon Barber

Final can be implemented in C++!

This topic is 5870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Example:
      
#define FINAL virtual private Loki::EmptyClass; 

class KeepenDerDamdinFuggerMuttensOotten : FINAL
   {
   };
    
A compliant C++ compiler will complain about an inaccessable ctor and/dtor of the base class if you attempt to derive from KeepenDerDamdinFuggerMuttensOotten. (Need I say that MSVC incorrectly compiles it... yes even VS.Net) [edit: fix the code block, and changed the name from FINALLY to Final] [edited by - Magmai Kai Holmlor on June 8, 2002 12:57:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi all, way back in the day when I was learning Java I learned what finally was...

I think what Magmai is trying to do here is prevent programmers from deriving from his base class KeepenDerDamdinFuggerMuttensOotten (cool name )

Java has this ability and C++ does not...

Dave "Dak Lozar" Loeser †

Share this post


Link to post
Share on other sites
I think a midly more intuitive solution would be to use a garbage collector (like Hans Boehm''s) that implements finalization, so you just register a function with the garbage collector for that object on creation, when it dies it will call it, just like Java, the notation maybe less natural, but I''m sure with a bit of fiddling you could easily make it look like Java''s notation.

Share this post


Link to post
Share on other sites
I believe you''re confusing the java keyword FINAL and FINALLY. FINALLY deals with exception handling, and FINAL means a class or function that can''t be overriden (and it is also a limited form of C++''s CONST keyword).

Share this post


Link to post
Share on other sites
quote:
Original post by abdulla
I think a midly more intuitive solution would be to use a garbage collector (like Hans Boehm''s) that implements finalization, so you just register a function with the garbage collector for that object on creation, when it dies it will call it, just like Java, the notation maybe less natural, but I''m sure with a bit of fiddling you could easily make it look like Java''s notation.

That''s not what he meant. C++ already has destructors for that purpose (minus the garbage collection of course). He is talking about declaring a class that can not be derived from (working similarly to Java''s ''final'' keyword on class declarations).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

A compliant C++ compiler will complain about an inaccessable ctor and/dtor of the base class if you attempt to derive from KeepenDerDamdinFuggerMuttensOotten.



C++ is a useful and flexible language, but why do we always have to resort to hacks to make it do the tricks we require? Commonly used constructs should be language features, not messy #define''s.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
C++ is a useful and flexible language, but why do we always have to resort to hacks to make it do the tricks we require?

Our requirements grow and change? Go figure...

For the record, I don''t get the point. finally, AFAIK, has to do with exceptions (I believe MSVC has a non-standard __finally along with __try and __catch) while final (Java) has to do with restricting inheritance. The two seem to be mixed up here.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!