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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:45:16+00:00 2026-06-02T02:45:16+00:00

I am having a problem with the following code, the overriden virtual functions are

  • 0

I am having a problem with the following code, the overriden virtual functions are not executing. Not sure i’m doing wrong here probably a silly mistake. Anyway this is a game project and I have an array of objects which looks like this (the core::array is an irrlicht array, similar to the vector array)

core::array<GameObject> gameTargets;

This is the GameObject and Zombie definition

class GameObject {
protected:
    scene::ISceneNode* node;
public:
    int ID;
    int hitpoints;

    GameObject() {
        ...
    };

    void setNode(scene::ISceneNode* inode) {
        ...
    }

    virtual void shot(int dmg) {
        ... [BREAKPOINT HERE]
    }

    scene::ISceneNode* getNode() {
        return node;
    }
};

class Zombie : public GameObject {
public:
    static const enum Animation {
        ZOMBIE_WALK,
        ZOMBIE_HURT,
        ZOMBIE_DIE,
        ZOMBIE_TWITCH,
        ZOMBIE_ATTACK,
        ZOMBIE_IDLE
    };

    //We only want to accepted animated mesh nodes for this object
    Zombie(int hp, scene::IAnimatedMeshSceneNode* inode) {
        ...
    }

    //Override the shot function
    void shot(int dmg) {
        ... [BREAKPOINT HERE]
    }

    //Animate the zombie
    void setAnimation(Animation anim) {
        ...
    }
};

The member functions of the derived classes is never called, I am creating the objects like this

Zombie target(hp, (scene::IAnimatedMeshSceneNode*)node);

and calling the virtual function like this

for(int i = 0; (u32)i<level->gameTargets.size(); i++) {
    if(selectedNode == level->gameTargets[i].getNode()) {
        level->gameTargets[i].shot(b->damage);
    }
}

where b is a pointer to a bullet with a int variable damage and gameTargets contains GameObject

  • 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-02T02:45:17+00:00Added an answer on June 2, 2026 at 2:45 am

    I suspect that you’re experiencing slicing because the gameTargets array contains values. I can’t tell for sure because I don’t know how the core::array template works. See What is object slicing? for a discussion about what slicing is.

    To fix this problem, store either raw pointers as in

    core::array<GameObject *> gameTargets;
    

    Or use some sort of reference-counted pointer like

    core::array<std::shared_ptr<GameObject>> gameTargets; // only available in C++11
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently having the problem of not able to run the following code
I am having problem with the following code. Delete function does not work (throws
I'm having a problem with the following code snippet: <!DOCTYPE html> <html> <head> <title>Hangman</title>
I'm having a problem getting a change event to register with the following code:
I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code
I'm having a problem with image scaling. When I use the following code to
I'm having a problem with the following VS 2010 code. Am trying to sort
I'm having a problem with the following code: string latString = 50.09445; float lat
I am having the following problem: Environment PHP, codeigniter framework with PDO. my code
I'm having a problem with the following code: #include <list> #include <boost/shared_ptr.hpp> #include Protocol/IMessage.hpp

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.