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:
The function it's talking about is this:Code:Error 9 error C2509: 'Initialize' : member function not declared in 'ScObj'
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.Code:void ScObj::Initialize() { //DOES STUFF. }
I do some hunting. There's a long inheritance chain involved here.
ok, so ScObj inherits from NetObj, right? I'm not being stupid here and missing something am I?Code:class ScObj : public NetObj { //CLASS STUFF, NO MENTION OF Initialize() }
It goes on:
Code:class NetObj : public SimObj { //CLASS STUFF }Code:class SimObj : public ConObj { //CLASS STUFF }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?)Code:class ConObj : public SimCom { //FINALLY, HERE'S Initialize()!!!! public: static void Initialize(); }
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.![]()
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!
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?
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:
? 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.Code:static void ScObj::Initialize() { // RANDOM STUFF }
OH, and by the way:
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?Must be defined differently for all member functions... but then shouldn't it be virtual?
Wow I changed my sig!
In conObj.cpp the function I'm wanting is defined:
That's what I meant when I said it was empty. Nothing between the braces.Code:void ConObj::Initialize() { }
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.
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!
That's a good question. I'll have to check.
But change it or not... it should be able to SEE it.
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!
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks