未定义对Class :: Function()C ++的引用 [英] undefined reference to Class::Function() C++

查看:125
本文介绍了未定义对Class :: Function()C ++的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

After searching for a solution to this for about a half an hour I have made no progress. The errors are as follows:

s\我的工作区\项目\main.cpp-第7行-未定义对'Sally :: Sally的引用()'

s\My Workspace\Project\main.cpp - Line 7 - undefined reference to 'Sally::Sally()'

s\My Workspace\Project\main.cpp-第9行-对'Sally :: printCrap()'的未定义引用

s\My Workspace\Project\main.cpp - Line 9 - undefined reference to 'Sally::printCrap()'

main.cpp

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

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

Sally.h

#ifndef SALLY_H
#define SALLY_H


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

#endif // SALLY_H

Sally.cpp

Sally.cpp

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

Sally::Sally(){
}

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

谢谢!

推荐答案

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

I know this is a pretty old question but maybe it could help someone.

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

So, when adding any additional files (headers, source, etc.) follow this (if using Eclipse or similar IDE):

新文件->文件...-> C / C ++头文件(源等)->接下来,接着->给它起一个名字,并确保它与您的项目位于同一路径,然后在构建目标中选中将文件添加到活动项目:全部选中->完成。

New file -> File... -> C/C++ header (source, etc.) -> next, next -> give it a name and make sure it's in the same path with your project, then check "Add file to active project", in build target(s): check all -> Finish.

希望有帮助。

这篇关于未定义对Class :: Function()C ++的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆