[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] adding constant to the operations properties



[Tue, 29 Jan 2002 13:23:10 -0800] a écrit:
> A quick question:  I'm not a C++ guru, so is it ever necessary in C++ to
> indicate that a method is *both* final and polymorphic?
> 
> For example (sorry about the syntax, it's been a few years...):
> 
>   class Foo {
>     public void bar() {
>       cout << "Foo";
>     }
>   }
> 
>   class Foo2 : Foo {
>     public virtual void bar() const {
>       cout << "Foo2";
>     }
>   }
> 
> I think this would mean that:
> 
>   1) a Foo2 that is cast as a Foo will
>      still output "Foo2" every time its
>      bar() method is called; and
> 
>   2) no class can override the Foo2
>      class's bar() method.
> 
> Is this a valid scenario?  I'm just wondering if maybe UML_POLYMORPHIC
> should be kept as a separate enumeration from UML_ABSTRACT /
> UML_FINAL...?  What do you think?

Foo2 * foo2 = new Foo2;
((Foo *) foo2)->bar() ouput "Foo" since bar in Foo's not virtual.
Actually a class Foo3 could override Foo2 bar method, wich will be called when casted to Foo3.
and "Foo2" for (Foo2 *) and "Foo" for (Foo *).
Although I thought gcc would output an error for overriden bar() in Foo2, I encountered no problems with that.

In fact, I implemented the UMLInheritance as an enum { UML_ABSTRACT, UML_POLYMORPHIC, UML_LEAF }, so that one can select only one, which is the proper behavior (I think). Since in C++, there is no way (http://www.parashift.com/c++-faq-lite/strange-inheritance.html) to make a Class or Method "final" or a "leaf", UML_LEAF can only be used in Java or in C++ by adding a /* final */ comment, with no technical effect. Since UML_LEAF _and_ UML_ABSTRACT is a non-sense, the enum is good.

> Which direction from Paris are you?  I've driven through the countryside
> to get to a po dunk little airport north of Paris (Beauvais or something
> like that), but haven't seen much else of the environs around the city. 
> However if I can ever get my act together and ameliorer mon francais
> (...!) I'd much rather be living in either France or Italy than on this
> ass-backwards continent.  One of these days...
> 
> Cheers Matthieu.  TTYL,
> 
> Johann

I'm in the south, near Massy. C'est une banlieue très agréable.
-- 
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. " 
	- Albert Einstein (1879-1955)

MaT|TaM
	 <mattam@netcourrier.com & mattam.selfhost.com>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK