gpt4 book ai didi

c++ - VC++ 说 "no overloaded function takes 7 arguments"我说是的!

转载 作者:太空狗 更新时间:2023-10-29 20:31:46 25 4
gpt4 key购买 nike

在我的 PDBComponent 类的头文件中,我刚刚为总共两个构造函数创建了一个新的构造函数:

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);
...

当我使用第一个构造函数时,我没有遇到任何编译错误。像这样:

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

但是,当我使用第二个构造函数时,出现编译错误::

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

编译错误:

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

我想也许我正在处理一个头文件,而编译器正在查看另一个头文件,所以我注释掉了第一个构造函数。编译器显示它正在重新编译 PDBComponent.cpp,然后显示错误:

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

...这表明编译器确实在查看正确的头文件。

有人知道为什么我会看到这种行为吗?

我正在使用 Visual Studios C++ 进行编译。


更多线索:

我刚刚在头文件中的类定义中添加了以下行:

bool trash() {return true;}

并用

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

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

在我的主文件中。编译时,再次编译 PDBComponent header 。我收到错误消息:

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

最佳答案

因此,当您在 header 中注释掉 6 参数构造函数时,您会在编译时遇到错误 - 但与包含对构造函数的调用的源文件相同?是否有可能以某种方式将不同的 header 用于该编译(可能涉及预编译 header 的怪异)。

尝试使用 /showIncludes 选项(IDE 项目设置中的“C++ | Advanced | Show includes”)和/或关闭预编译 header ,看看您是否获得了更多线索或更好的行为。

关于c++ - VC++ 说 "no overloaded function takes 7 arguments"我说是的!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3496754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com