Connecting Tech Pros Worldwide Help | Site Map

something like java interface?

cmk128@hotmail.com
Guest
 
Posts: n/a
#1: Mar 27 '06
Hi
How can we force all the class A's subclass inherit all its
functions? Or how can we force class B to inherit function abc()?
thanks
from Peter (cmk128@hotmail.com)

class A{
public:
virtual void abc();
};

class B:public A{
};

int main(){
return 0;
}

Jakob Bieling
Guest
 
Posts: n/a
#2: Mar 27 '06

re: something like java interface?


cmk128@hotmail.com wrote:[color=blue]
> Hi
> How can we force all the class A's subclass inherit all its
> functions? Or how can we force class B to inherit function abc()?[/color]

There is no need to. All classes that you derive from A will
automatically inherit all member functions of A.
[color=blue]
> class A{
> public:
> virtual void abc();
> };
>
> class B:public A{
> };
>
> int main(){
> return 0;
> }[/color]

hth
--
jb

(reply address in rot13, unscramble first)


Thomas Maier-Komor
Guest
 
Posts: n/a
#3: Mar 27 '06

re: something like java interface?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jakob Bieling wrote:[color=blue]
> cmk128@hotmail.com wrote:[color=green]
>> Hi
>> How can we force all the class A's subclass inherit all its
>> functions? Or how can we force class B to inherit function abc()?[/color]
>
> There is no need to. All classes that you derive from A will
> automatically inherit all member functions of A.
>[color=green]
>> class A{
>> public:
>> virtual void abc();
>> };
>>
>> class B:public A{
>> };
>>
>> int main(){
>> return 0;
>> }[/color]
>
> hth[/color]

to force the implementor of the deriving class to do his own
implementation, add a "= 0" to the declaration of the method.

I.e.:

class A {
public:
virtual void abc() = 0;
};

HTH,
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (SunOS)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEJ/nJ6U+hp8PKQZIRAsD6AKCYwzaPtpsRZYyACUxXoLFMLMFWyQCg tsUd
t4Wop7dOk0nGTdvWMwMXYL0=
=R/en
-----END PGP SIGNATURE-----
Closed Thread