something like java interface?

C

cmk128

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 ([email protected])

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

class B:public A{
};

int main(){
return 0;
}
 
J

Jakob Bieling

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()?

There is no need to. All classes that you derive from A will
automatically inherit all member functions of A.
class A{
public:
virtual void abc();
};

class B:public A{
};

int main(){
return 0;
}

hth
 
T

Thomas Maier-Komor

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

Jakob said:
There is no need to. All classes that you derive from A will
automatically inherit all member functions of A.


hth

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+hp8PKQZIRAsD6AKCYwzaPtpsRZYyACUxXoLFMLMFWyQCgtsUd
t4Wop7dOk0nGTdvWMwMXYL0=
=R/en
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top