Jump to content
  • Advertisement
Sign in to follow this  
Wavesonics

C++ Abstract classes as Interfaces

This topic is 4099 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm trying to use a pure virtual class as an Interface. Thus I could have a function accept the interface like:
Quote:
class SomeInterface { virtual void interfaceFunction() = 0; } void f( SomeInterface obj );
But I get a compilation error obviously saying "SomeInterface does not implement pure virtual function 'interfaceFunction'". So I did:
Quote:
class SomeInterface { virtual void interfaceFunction() {} }
Which works, but of course, now does not require inheriting classes to over ride the interface function. So how should this be done?

Share this post


Link to post
Share on other sites
Advertisement
f( SomeInterface obj ); defines a function which takes an instance of SomeInterface, which is impossible (such an instance cannot exist, because SomeInterface is abstract).

Have f take a reference or pointer to an object instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!