Jump to content
  • Advertisement
Sign in to follow this  
noodleBowl

C++ Interfaces

This topic is 991 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

I'm looking for some help. Basically, I am trying to make a class called RenderPackage, which would contain a shader and a few other items.
But for this example, I am focused on the shader part.
 
In the RenderPackage, the shader member  would be some type of shader. EG a default shader, a red light shader, and etc
Here I figured a Interface would work best, where all of my shaders would be able to implement this interface
 
So (I think) I made a interface for my shaders:

class IShader
{
public:
   virtual ~IShader();
   virtual void Use() = 0;
};

Then I have my render package:

class RenderPackage
{
public:
   IShader shader;
};

But I am getting an error for my RenderPackage class:
object of abstract class type "IShader" is not allowed. Function "IShader::Use" is a pure virtual function
 
So my question is:
How should I really be doing this? How can you use a Interface class as a member.
I was hoping I would be able to do something like:
 

DefaultShader defaultShader;
 
RenderPackage package;
package.shader = defaultShader;
 
//Down the line
package.shader.Use();
Edited by noodleBowl

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!