[C++] Compilation and default values problem.

Started by
13 comments, last by Zahlman 14 years, 1 month ago
Hi community. I have a class Shooter and its constructor's declaration is:

//Shooter.h

Shooter(int health=0, float speed=250.0f, float jumpPower=600.0f, int    munitions=1);

As you can see, each argument has its default value. I have a class Level and in its private part has:

// Level.h that includes "Shooter.h"


private:

    Shooter m_mainCharacter;

And its constructor definition is:

// Level.cpp that includes "Level.h"

Level() : m_mainCharacter(1, 300.0f) 
{

   // Irrelevant things

}

Hence, in its initialization list I don't put a value for jumpPower, then jumpPower takes its default value. The problem is the following: Suppose I modify the default value for jumpPower in Shooter.h. When I compile and run the application there isn't a change!!!! But if I make an irrelevant change in Level.cpp like a newline, or space, etc, when I recompile and run, the behavior is the correct.
Advertisement
Wow, that does seem like a build dependency bug to me. What compiler or makefile system are you using?
This has nothing to do with default parameters.

Use a build environment that has a (working) dependency checker, like, er, well, I can't even think of one that doesn't...
Maybe you're using broken makefiles?
Thanks for the answers.
I'm using Visual Studio 2008.
Very weird. Visual Studio's dependency checking is usually solid and the only way to screw it up that I am aware makes it recompile everything all the time. And that's obviously not your problem...
Something is confusing the dependency checker... which usually works the other way around like Rattenhirn said.


Do you have multiple files with the name "Level.h" or "Shooter.h" anywhere else in your project or directory structure that the dependency checker might be looking at, which are different from what the compiler ends up including?
I deleted the project and I made another and I have the same result.
I checked the files and all have unique names.
Are all the .h files as well as all the .cpp files added to the project?
I discovered the reason, but it's SO WEIRD!!!!!

If I change the default value for jumpPower in Shooter.h the compiler output is:

------ Build started: Project: CaperucitaPlusPlus, Configuration: Debug Win32 ------
Compiling...
Shooter.cpp
Generating Code...
Skipping... (no relevant changes detected)
Level.cpp
mainLevel.cpp
Linking...
Embedding manifest...
Build log was saved at "file://d:\NicoDocs\Programming\SFML\CaperucitaPlusPlus\CaperucitaPlusPlus\Debug\BuildLog.htm"
CaperucitaPlusPlus - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Apparently the compiler skips Level.cpp compilation because for him "no relevant changes detected".
But if I put a newline, or space in Shooter.h, A REAL IRRELEVANT CHANGE!!!! the compiler output is:

------ Build started: Project: CaperucitaPlusPlus, Configuration: Debug Win32 ------
Compiling...
Shooter.cpp
Generating Code...
Compiling...
Level.cpp
mainLevel.cpp
Generating Code...
Linking...
Embedding manifest...
Build log was saved at "file://d:\NicoDocs\Programming\SFML\CaperucitaPlusPlus\CaperucitaPlusPlus\Debug\BuildLog.htm"
CaperucitaPlusPlus - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Then we can see that Level.cpp compiles and the result is what I need.


JAJAJAJAJA I don't know what to say!!!! Changing a value is less relevant than a newline or space?
I searched in the web and I found this

Maybe a Visual Studio Bug

That post is from 2005 and the guy had my same problem. Apparently there isn't a solution, maybe it's a Visual Studio bug.

This topic is closed to new replies.

Advertisement