2016-11-12 84 views
-1

我不确定这个问题是否与我的IDE一样,但我尝试了Code :: Blocks和Visual Studio两个项目,所以我不认为它是。对“Class :: method”C++的未定义引用?

我的主文件:

#include <iostream> 
#include "Hello.h" 

using namespace std; 

int main() 
{ 
    Hello firstMan; 

    firstMan.greeting(); 
    firstMan.goodbye(); 
    firstMan.goodbye(); 
} 

我Hello.h:

#ifndef HELLO_H_INCLUDED 
#define HELLO_H_INCLUDED 

class Hello 
{ 
    public: 
     void greeting(); 
     void goodbye(); 
}; 

#endif // HELLO_H_INCLUDED 

我的类文件Hi.cpp:

#include <iostream> 
#include "Hello.h" 

using namespace std; 

void Hello::greeting() 
{ 
    cout << "Hello" << endl; 
} 

void Hello::goodbye() 
{ 
    cout << "Bye" << endl; 
} 

我刚开始C++,所以我很抱歉,如果这是一个简单的错误或只是一个错字。

回答

1

该代码看起来很好。

您似乎没有将Hi.cpp添加到您的IDE项目中。

奇怪的是,你没有叫它Hello.cpp - 你有一个的文件名称(也许是空的),而你正在建造呢?