现在我正在学习基础数据结构在C++通过埃利斯霍洛维茨写的,想实现的例子77页。但是,当我生成项目时,Eclipse控制台显示一些警告。LD:符号(S)没有发现
这是我的头文件:
#ifndef RECTANGLE_H_
#define RECTANGLE_H_
class Rectangle{
public:
Rectangle();
~Rectangle();
int GetHeight();
int GetWidth();
private:
int xLow, yLow, height, width;
} ;
#endif
这是我的源文件:
#include <iostream>
#include "Rectangle.h"
using namespace std;
int main(){
Rectangle r, s;
Rectangle *t = &s;
if(r.GetHeight()*r.GetWidth() > t->GetHeight()*t->GetWidth())
cout << "r";
else
cout << "s";
cout << "has the greater area" << endl;
return 0;
}
而且CDT构建控制台显示:
Building target: rectangle
Invoking: MacOS X C++ Linker
g++ -o "rectangle" ./main.o
Undefined symbols:
"Rectangle::Rectangle()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetWidth()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetHeight()", referenced from:
_main in main.o
_main in main.o
"Rectangle::~Rectangle()", referenced from:
_main in main.o
_main in main.o
_main in main.o
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rectangle] Error 1
**** Build Finished ****
此外,将二进制文件自动创建在建立项目之后?
您没有给出任何代码。 '矩形'构造函数。 – 2012-03-10 16:40:41