calling a parent class's function doesn't change data members?

This is a discussion on calling a parent class's function doesn't change data members? within the C++ Programming forums, part of the General Programming Boards category; I'm working on a simple inheritance system for graphics objects in a game engine, but I've hit a snag with ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    calling a parent class's function doesn't change data members?

    I'm working on a simple inheritance system for graphics objects in a game engine, but I've hit a snag with calling the functions of a class that I've inherited from. In my code, I have Model inherited from Transform, and I want to call Transform::init from Model::init. To do this, I have code like:
    Code:
    //transform.h
    class Transform {
    protected:
        SceneNode* sceneNode;
    public:
        void init();
    };
    
    //transform.cpp
    void Transform::init() {
        sceneNode = new SceneNode(/*etc*/);
        //here sceneNode is a good pointer
    }
    
    //model.h
    class Model : public Transform {
    public:
        void init();
    };
    
    //model.cpp
    void Model::init() {
        Transform::init();
         //here sceneNode is null
    }
    I don't understand why Transform::init() isn't setting sceneNode in the inherited class. Is there something I need to change in the declarations, or do I need to call Transform::init() differently, or am I just doing something completely wrong?
    Illusion and reality become impartiality and confidence.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    There is nothing wrong I can see with that piece of code, ichijoji. How are you testing the pointer?

    Maybe it's best if you also provide details for SceneNode. Most particularly its constructor(s).
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    I'm testing the pointer using printf("%p\n",sceneNode). As for SceneNode, it's an Ogre class and the docs for it are here. Now that I have confirmation that it isn't some stupid c++ thing, I'll try asking the ogre guys directly.
    Illusion and reality become impartiality and confidence.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21