Connecting Tech Pros Worldwide Help | Site Map

something like java interface?

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 27th, 2006, 01:45 PM
cmk128@hotmail.com
Guest
 
Posts: n/a
Default something like java interface?

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, 01:45 PM
Jakob Bieling
Guest
 
Posts: n/a
Default 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, 01:55 PM
Thomas Maier-Komor
Guest
 
Posts: n/a
Default 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-----
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.