Final can be implemented in C++!

Started by
71 comments, last by Shannon Barber 21 years, 9 months ago
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]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
That''s not a very clear example =/
I think I speak for everyone when I post this:

...?
It''s been a while but IIRC it''s finaly is a Java thing. I must confess I forgot what it was for
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 †
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
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.
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).
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).

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

This topic is closed to new replies.

Advertisement