Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Inheritance issue

  1. #1
    MerakSpielman is offline Learning Programmer
    Join Date
    Jan 2008
    Posts
    44
    Rep Power
    0

    Inheritance issue

    I'm assuming that's what this is...

    I'm working on a fairly large software package. I was basically handed it and told "figure this out." It's actually fairly fun most of the time.

    Of course I wouldn't have been handed it if it didn't have problems. I've managed to fix all of the compile errors except one... and it's been giving me hell.

    I'll try to summarize it as best I can. I can't reprint any of the actual code because it's proprietary.

    The compile error:
    Code:
    Error	9	error C2509: 'Initialize' : member function not declared in 'ScObj'
    The function it's talking about is this:
    Code:
    void ScObj::Initialize() 
    {
       //DOES STUFF.
    }
    OK, that seems simple enough. Clearly the ScObj class (or one of its parents) is supposed to have an Initialize() declaration, and for some reason it's not there.

    I do some hunting. There's a long inheritance chain involved here.

    Code:
    class ScObj : public NetObj
    {
       //CLASS STUFF, NO MENTION OF Initialize()
    }
    ok, so ScObj inherits from NetObj, right? I'm not being stupid here and missing something am I?

    It goes on:
    Code:
    class NetObj : public SimObj
    {
       //CLASS STUFF
    }
    Code:
    class SimObj : public ConObj
    {
       //CLASS STUFF
    }
    Code:
    class ConObj : public SimCom
    {
       //FINALLY, HERE'S Initialize()!!!!
    
       public:
         static void Initialize();
    }
    YES! I've traced down where Initialize is supposed to have come from! (interestingly, the definition for ConObj::Initialize() is empty - no code at all. Must be defined differently for all member functions... but then shouldn't it be virtual?)

    Only problem is... you can tell by the compile error that the child class can't see it. Why not?? Everything in the whole chain is public. My understanding is that every method of every parent should be accessible by every child.

    The actual inheritance tree is fairly complex, with lots of branching that I've left out. Here is a list of things I've tried and most of which had disastrous consequences (that is to say, my error count went from 2 up to 200 or more in most of them):

    #included the file which contains ConObj into the beginning of the file with the ScObj class.
    Made ConObj a friend of ScObj.
    Inserted a new void Initialize() function into ScObj.
    Changed the declaration of Initialize in ConObj from static to virtual. (BAD IDEA)
    Commented out the problem function (BAD IDEA).


    So any ideas here? What am I missing? Lots of other classes seem to call Initialize() without any problems.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Inheritance issue

    I think that void ScObj::Initialize() needs to be declared as static. You can't have a static member function of a class be overloaded by a non-static member function.

    EDIT: That error indicates that you did declare it as static inside of the class definition, but not when you wrote the function implementation in the .cpp file. At least that's how I read it...
    Wow I changed my sig!

  4. #3
    MerakSpielman is offline Learning Programmer
    Join Date
    Jan 2008
    Posts
    44
    Rep Power
    0

    Re: Inheritance issue

    Quote Originally Posted by ZekeDragon View Post
    I think that void ScObj::Initialize() needs to be declared as static. You can't have a static member function of a class be overloaded by a non-static member function.
    Just tried it real quick. Same error.

    Just as an experiment I went one level up the inheritance chain, where the methods for netObj were being coded, and typed "netObj::" and all the methods popped up in the tooltip, including Initialize().

    But when I try the same thing for the child class ScObj... the :: menu lists the methods for one level up (netObj) but no higher. It's not following the inheritance chain all the way up to where Initialize() is.

    This is driving. me. nuts. Why would it work for one class and not be passed down to its child?

  5. #4
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Inheritance issue

    Hmm... that IS odd, but I'd check the includes in whatever header contains the netObj definition and see if everything is there and... was the change to this:
    Code:
    static void ScObj::Initialize()
    {
        // RANDOM STUFF
    }
    ? I don't mean to say that you misinterpreted, it just sounds really odd that this would happen, because yes, the class should inherit all parent methods and properties.

    OH, and by the way:
    Must be defined differently for all member functions... but then shouldn't it be virtual?
    You CANNOT make a static function virtual. In fact, I'd presume that static void Initialize isn't empty, did you check the according .cpp file with that? If Initialize is static, I believe that it requires a member body, even if it's empty. You could try adding an empty function to the Initialize in the parent object?
    Wow I changed my sig!

  6. #5
    MerakSpielman is offline Learning Programmer
    Join Date
    Jan 2008
    Posts
    44
    Rep Power
    0

    Re: Inheritance issue

    In conObj.cpp the function I'm wanting is defined:

    Code:
    void ConObj::Initialize()
    {
    }
    That's what I meant when I said it was empty. Nothing between the braces.

    When I open netObj.cpp I can type "void netObj::" and the tooltip will pop up, listing (among a multitude of other things) Initialize().

    Ditto with simObj.cpp.

    But when I get down to ScObj.cpp it stops working. It has the methods for its direct parent, but no higher.

    There's gotta be an include somewhere I'm missing, or something. I'll double check the includes, but then I gotta go to bed. Shouldn't stay up too late. Can't program if I'm getting fuzzy.

  7. #6
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Inheritance issue

    Hmm... wait, this may be an exercise in futility.

    I don't think you can actually do this with a static member function. Do other functions perform this just fine? The thing about static functions is there's only one of them, so changing it may be prohibited, even for derived classes. Do any other member classes actually change Initialize()?
    Wow I changed my sig!

  8. #7
    MerakSpielman is offline Learning Programmer
    Join Date
    Jan 2008
    Posts
    44
    Rep Power
    0

    Re: Inheritance issue

    That's a good question. I'll have to check.


    But change it or not... it should be able to SEE it.

  9. #8
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Inheritance issue

    Yeah, just did the research, you cannot override a static function at all.

    You'll need to come up with another solution!

    EDIT: I'll be sure to hear about THIS tomorrow...
    Wow I changed my sig!

  10. #9
    Join Date
    Jul 2006
    Posts
    16,525
    Blog Entries
    75
    Rep Power
    144

    Re: Inheritance issue

    Have you tried redeclaring the Initialize method in ScObj?
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  11. #10
    MerakSpielman is offline Learning Programmer
    Join Date
    Jan 2008
    Posts
    44
    Rep Power
    0

    Re: Inheritance issue

    Quote Originally Posted by WingedPanther View Post
    Have you tried redeclaring the Initialize method in ScObj?
    Yes. That seems to confuse things. I get tons of errors.

    I'm digging into this again today. I'm really a fairly novice programmer, and this job is more than a little beyond my abilities. I'm very proud I managed to stomp the last 30 bugs. But this ones a doozy.

    I'm going to see if I can find other instances where things use Initialize() without errors, propagating up the same inheritance tree. Maybe if I can figure out what they're doing I can figure out what this one's supposed to be doing.

    I also want to see what, if anything, is actually calling this function. I know I get errors if I simply comment it out, so something out there is depending on it.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. A few problems with Inheritance
    By brutetal in forum Java Help
    Replies: 5
    Last Post: 05-23-2010, 03:03 AM
  2. INHERITANCE: reason behind that??
    By himanshu in forum Java Help
    Replies: 3
    Last Post: 01-17-2010, 09:15 AM
  3. Dynamic inheritance in c++
    By aftos in forum C and C++
    Replies: 6
    Last Post: 07-15-2009, 11:43 PM
  4. Inheritance
    By fread in forum Java Help
    Replies: 5
    Last Post: 01-30-2009, 01:41 AM
  5. C++ Inheritance help!?
    By rossen in forum C and C++
    Replies: 7
    Last Post: 06-11-2008, 10:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts