//point类头文件:point.h
#ifndef _POINT_H_
#define _POINT_H_
#include <iostream>
class point
{
public:
point(int x=0,int y=0) : x(x),y(y) {}
void GetPoint();
private:
int x;
int y;
};
#endif
//point类的实现文件:point.cpp
#include "point.h"
inline void point::GetPoint()
{
std::cout << "(" << x << "," << y << ")" << std::endl;
}
//使用point的类:testPoint.cpp
#include "point.h"
int main()
{
point p(2,5);
p.GetPoint();
return 0;
}
单独编译 testPoint.cpp时,出现以下错误:
--------------------Configuration: pointTest - Win32 Debug--------------------
Compiling...
pointTest.cpp
Linking...
pointTest.obj : error LNK2001: unresolved external symbol "public: void __thiscall point::GetPoint(void)" (?GetPoint@point@@QAEXXZ)
Debug/pointTest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
pointTest.exe - 2 error(s), 0 warning(s)
建立一个控制台应用程序工程的时候,把point类和他的实现文件加入工程后编译,也是出现上面的错误,请教高手,这是为什么?