views:

132

answers:

2

In my PDBComponent class's header file, I just created a new constructor for a grand total of two constructors:

class PDBComponent {
    public:
        PDBComponent(string name,double min_current,double nom_current,
                     double max_current, EPSCommands* command_ptr, double delay);
        PDBComponent(string name,double min_current,double nom_current,
                     double max_current, EPSCommands* command_ptr, EPSFault* fault_ptr ,double delay);
...

And when I use the first constructor, I get no compile error. Like so:

PDBComponent component = PDBComponent("STX"     ,0.1,  0.5,  1.0
        ,new EPSCommands( 1.0, 3.0),0.0);

However when I use the second constructor I get a compile error::

PDBComponent component = PDBComponent("STX"     ,0.1,  0.5,  1.0
        ,new EPSCommands( 1.0, 3.0), new EPSFault(EPSFault::OpenCircuit,2.0),0.0);

The compile error:

error C2661: 'fs5system::PDBComponent::PDBComponent' : no overloaded function takes 7 arguments

I thought that maybe I was working with one header file while the compiler was looking at another, so I commented out the first constructor. The compiler showed that it was recompiling the PDBComponent.cpp and then showed an error:

error C2511: 'fs5system::PDBComponent::PDBComponent(std::string,double,double,double,fs5system::EPSCommands *,double)' : overloaded member function not found in 'fs5system::PDBComponent'

...which indicates that the compiler is indeed looking at the correct header file.

Anybody know why I'm seeing this behavior?

I'm compiling with Visual Studios C++.


More Clues:

I just added the following line to the class definition in the header file:

bool trash() {return true;}

And tested it with

PDBComponent* component;
component = new PDBComponent("STX"     ,0.1,  0.5,  1.0
        ,new EPSCommands( 1.0, 3.0),0.0);

cout << component->trash() << endl;

in my main file. When compiling, the PDBComponent header is again compiled. I get error message:

error C2039: 'trash' : is not a member of 'fs5system::PDBComponent'

+1  A: 

My psychic debugging powers think EPSFault is not defined where you're using it there, or that this class is being included in a precompiled header (in which case that header needs to be rebuilt).

Note that the code there is NOT exception safe because you've put two news in a single statement -- if the first one succeeds, and the second throws std::bad_alloc, then the memory allocated by the first is leaked.

Billy ONeal
+1 For the "exception safe" comment. I'm new to C++ and today I'm really feeling the GOTCHAS!
John Berryman
I'll give you another +1 if you can tell me where to get a psychic debugger.
John Berryman
@John: His name is Raymond Chen.
Billy ONeal
+4  A: 

So, you get an error when the 6-parameter constructor is being compiled when you've commented it out in the header - but is that the same source file that contains the calls to the constructor? Is it possible that a different header is being used for that compilation somehow (maybe precompiled header weirdness is involved).

Try using the /showIncludes option ("C++ | Advanced | Show includes" in the IDE's project settings) and/or turning off precompiled headers and see if you get any further clues or better behavior.

Michael Burr
I'm trying /showIncludes... there's a lot of includes it seems... and I think you might be the winner... stay tuned!
John Berryman
So what exactly was the problem?
Tomek
grepping through the /showIncludes output for the particular header's name will probably net you good results really quickly...
Michael Burr
And we have a winner! Thank you so much. I did a lot of refactoring with my project this morning and in the process I had duplicate files wondering around. Although I thought the files in my solution explorer were all pointing to the new directory, some were still pointing at the old directory, and so I was editing a different file than I thought I was. /showIncludes pointed this out. (Inserting /showIncludes in my c++ toolbox.)
John Berryman