Connecting Tech Pros Worldwide Help | Site Map

something like java interface?

  #1  
Old March 27th, 2006, 02:45 PM
cmk128@hotmail.com
Guest
 
Posts: n/a
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;
}

  #2  
Old March 27th, 2006, 02:45 PM
Jakob Bieling
Guest
 
Posts: n/a

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)


  #3  
Old March 27th, 2006, 02:55 PM
Thomas Maier-Komor
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is C++ faddish like Java? wee answers 25 August 6th, 2005 10:15 PM
C++ objects that act like Java/C# objects. Steven T. Hatton answers 8 July 23rd, 2005 06:47 AM
Empty base class (like Java's "interface")? Markus Dehmann answers 3 July 22nd, 2005 12:24 PM
dynamic class/module use? (like Java's forName) Alex Hunsley answers 14 July 18th, 2005 01:57 PM