我收到了一个不存在的内容的未定义引用错误
当我尝试编译此代码时
Analysis2::Analysis2() //line 13
{
Seconds_v = 0; //Seconds_v and Seconds_t are both of type int
Seconds_t = 0; //and declared in header
}
,出现此错误
analysis2.cpp:13:对`FileParameters :: FileParameters()'的未定义引用
为什么它给我该未定义的引用? FileParameters 是 Analysis2 中包含的一个类,如果有帮助的话,在 Analysis2 头文件中定义了一个 FileParameters 对象。
When I try to compile this code
Analysis2::Analysis2() //line 13
{
Seconds_v = 0; //Seconds_v and Seconds_t are both of type int
Seconds_t = 0; //and declared in header
}
I get this error
analysis2.cpp:13: undefined reference to `FileParameters::FileParameters()'
Why is it giving me that undefined reference? FileParameters is a class included in Analysis2 and there is a FileParameters object defined in the Analysis2 header file if that helps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您有构造函数时,如果您没有在初始值设定项列表中显式构造每个成员变量,则每个成员变量都会自动默认构造。上面的代码自动扩展为:
如果您还没有实现
FileParameters
的默认构造函数,或者甚至没有可访问的构造函数,这就是您收到的错误。When you have constructor, every member variable is automatically default-constructed if you don't explicitly construct it in the initializer list. Your code above automatically expands to:
And if you didn't implement the default constructor of
FileParameters
yet, or don't even have an accessible one, that's the error you get.Analysis2 类(该死的可怕名字,顺便说一句)可能是使用 FileParameters 实现的。您需要链接两个类的对象 - 仅仅包含标头是不够的。但可以肯定的是,我们需要看到更多代码。
The Analysis2 class (bloody awful name, BTW) is probably implemented using FileParameters. You need to link the objects for both classes - simply including the header is not enough. But to be sure, we would need to see more code.