VC++ says "no overloaded function takes 7 arguments" I say YES IT DOES!
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'
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.
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 new
s 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.
精彩评论