Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:11:21+00:00 2026-05-25T18:11:21+00:00

I am relatively new to C++ and I have been working on a basic

  • 0

I am relatively new to C++ and I have been working on a basic 3D rendering engine using OpenGL.I have the following issue:
I have a class called GeomEntity which is the base class for all geometry primitives.I have another class called DefaultMaterial which is the base class for all materials(consists of different types of shader programs) .Because I am going to have many types of materials like :ColorMaterial,TextureMaterial,AnimatedMaterial and so on I need to put a reference to the material in GeomEntity class so that from the main app I can set any of the material with this function:

  void GeomEntity ::addMaterial (const DefaultMaterial *mat){

         material=mat;////material is the member variable pointer of type DefaultMaterial

  }

But the thing is that although all of those materials are derived from the DefaultMaterial they all have got their unique methods which I can’t trigger if I reference them to the variable of DefaultMaterial by default.
So for example in the main application:

  Sphere sphere;
  ....
  sphere.addMaterial(&animMaterial);///of type AnimatedMaterial
  sphere.material->interpolateColor(timerSinceStart);
   ///doesn't happen anything  as the sphere.material is
  /// of type DefaultMaterial that has   no interpolateColor() method

I know I have can use templates or casts but I would like to hear about the best practices of this kind of polymorphism in C++ .In Java or C# I would really use something like this:

((AnimatedMaterial)sphere.material).interpolateColor(timerSinceStart);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:11:22+00:00Added an answer on May 25, 2026 at 6:11 pm

    In C++ you can do this using dynamic_cast, that is I believe closest equivalent of that C# feature:

    AnimatedMaterial* panim = dynamic_cast<AnimatedMaterial*>(sphere.material);
    if(panim) 
      panim->interpolateColor(timerSinceStart);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to OpenGL and have been using the GLTools library it provides.
I'm relatively new to using PHP and have been working on using it to
I'm relatively new to NHibernate, but have been using it for the last few
I am relatively new to using TDD and have been reading about mocking objects
I'm relatively new to PHP and have been writing a project using what I
I'm relatively new to java (specifically swing) and have recently been making some fairly
I'm relatively new to SVN and have a rather basic question. I have several
I'm fairly new to Git, and have been working with it for only 3
I'm relatively new to version control, and so far only have experience working with
I am relatively new to PHP/MySQL and have been having a problem that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.