c++ - 对 Class::Function() C++ 的 undefined reference

标签 c++ codeblocks

<分区>

在寻找解决方案大约半小时后,我没有取得任何进展。 错误如下:

s\My Workspace\Project\main.cpp - 第 7 行 - 对“Sally::Sally()”的 undefined reference

s\My Workspace\Project\main.cpp - 第 9 行 - 对“Sally::printCrap()”的 undefined reference

主要.cpp

#include <iostream>
using namespace std;
#include "Sally.h"

int main()
{
    Sally sallyObject;
    sallyObject.printCrap();
}

莎莉.h

#ifndef SALLY_H
#define SALLY_H


class Sally
{
    public:
        Sally();
        void printCrap();
};

#endif // SALLY_H

莎莉.cpp

#include "Sally.h"
#include <iostream>
using namespace std;

Sally::Sally(){
}

void Sally::printCrap(){
    cout << "Did someone say steak?" << endl;
}

提前致谢!

最佳答案

我知道这是一个很老的问题,但也许它可以帮助某人。

因此,在添加任何其他文件( header 、源代码等)时,请遵循以下步骤(如果使用 Eclipse 或类似的 IDE):

New file -> File... -> C/C++ header (source, etc.) -> next, next -> 给它起个名字,确保它和你的项目在同一个路径,然后勾选“Add文件到事件项目”,在构建目标中:选中所有 -> 完成。

希望对您有所帮助。

关于c++ - 对 Class::Function() C++ 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34982333/

相关文章:

c++ - Eclipse/Code::Block 不运行应用程序

c++ - 不让一个值超过另一个值的最快方法 - C++

c++ - 启动时未应用构造函数值

c++ - 这两个 C++ 语句有什么区别?

c - 尝试使用 pdcurses 扩展库时出现与 gdi32 相关的错误

调用函数两次后 C++ .exe "has stopped working"

c++ - at() 和 row().col() 之间的区别

函数参数的 C++ 类模板推导 (P0091R0)

java - 将可执行文件链接到代码块

c++ - 如何让 Code::Blocks 在同一目录中显示 .h 和 .cpp 文件?