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 7842117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:14:40+00:00 2026-06-02T16:14:40+00:00

I think I should start by simplifying my class structure so I can better

  • 0

I think I should start by simplifying my class structure so I can better explain my problem, which I suspect might just be a misunderstanding of the use of virtual.

I have:

class Controller{
..
    virtual void InitialiseController(){ //std::cout confirms this is running }
..
}

class AIController : public Controller{
..
    virtual void InitialiseController(){ //some logic here }
..
}
class ComController : public AIController{
..
    virtual void InitialiseController(){ //actually the same logic as parent }
..
}

My object, Snake, has a pointer to a Controller (Controller* _controller). When I call the snake.initialise(..) method I pass it a new ComController object which then sets snakes _controller equal to the new ComController. I know that that process works successfully.

But when I then call _controller.InitialiseController(); my debugger shows the program steps into the base class Controller’s blank implementation of InitialiseContoller.

I know I’ve probably oversimplified and you might not be able to help, but I think perhaps it’s something I’m not understanding about the whole concept, a logic error, rather than a typed error and would like to check.

Additional code:

_player2->Initialise(_gameProperties, &_fruitManager, new ComController(_player2), _player1);

stepping in ..

void Snake::Initialise(
   GamePropertiesManager* gpm, FruitManager* fm, Controller* control, Snake* opposingSnake)
{
   _game = gpm;
   _fruitManager = fm;
   _controller = control;
   _opposition = opposingSnake;

   if(_controller){

           ///Bunch of stuff in here runs just fine


      // This primarily serves to ensure that a ComControllers timer is started, but other controllers might wish to override initialise later
      _controller->IntialiseController();

   }

}
  • 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-06-02T16:14:43+00:00Added an answer on June 2, 2026 at 4:14 pm

    I don’t really see anything wrong with what you’re doing (at least as far as understanding and using virtual methods).

    Here’s a complete example. Please compare it with your code.

    #include <stdio.h>
    
    class Controller{
    public:
        virtual void InitialiseController(){
          printf ("base class controller...\n");
        }
    };
    
    class AIController : public Controller{
    public:
        virtual void InitialiseController(){
          printf ("AIController subclass controller...\n");
        }
    };
    
    class ComController : public AIController{
    public:
        virtual void InitialiseController(){
          printf ("ComController subclass controller...\n");
        }
    };
    
    int main (int argc, char *argv[])
    {
       Controller *myController = new ComController ();
       myController->InitialiseController ();
       return 0;
    }
    

    Compile:
    g++ -Wall -pedantic -o tmp tmp.cpp

    Execute:
    ComController subclass controller...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which I think should compile, but doesn't: import java.io.InputStream; import
This might be something very straight forward and I really think it should work
I think this is wrong, it should start as NULL and not with a
From what I can read on json.org , all JSON strings should start with
I am new to Facebook development. Where do you think I should start learning.
I have what I think should be a fairly simple mapping issue, but not
I'm working on UVa #112 Tree Summing . I have what I think should
I think it should be possible to add additional namespaces to the generated classes
I think there should be a tool to do so ? is anyone here
I think it should be 01 but someone says its undefined, any reason for

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.