这是我的基类 Shape.h
#ifndef Shape_H
#define Shape_H
#include <iostream>
using namespace std;
class Shape
{
protected:
string name;
bool containsObj;
public:
Shape();
Shape(string, bool);
string getName();
bool getContainsObj();
double computeArea();
};
#endif
形状.cpp
#include "Shape.h"
Shape::Shape(string name, bool containsObj)
{
this -> name = name;
this -> containsObj = containsObj;
}
string Shape:: getName()
{
return name;
}
bool Shape::getContainsObj()
{
return containsObj;
}
这是我的子类。交叉.h
#ifndef Cross_H
#define Cross_H
#include <iostream>
#include "Shape.h"
using namespace std;
class Cross: public Shape
{
protected:
int x[12];
int y[12];
public:
Cross();
double computeArea();
};
#endif
交叉.cpp
#include "Cross.h"
Cross::Cross()
{
for (int i = 0; i < 12; i++)
{
this -> x[i] = 0;
this -> x[0] = 0;
}
}
Shape 和 Cross 位于不同的文件中,但在同一个文件夹中。奇怪的是,当我编译它时,出现了我以前从未见过的错误,例如“在函数'ZN5CrossC1Ev'中,未定义对 Shape::Shape() 的引用,'ZN5CrossC1Ev',未定义对 Shape::Shape() 的引用, 未定义对 WinMain@16 的引用”。
我试着自己做一些调试。当我删除 Cross 构造函数时,它工作正常。但我绝对需要它。谁能给我解释一下?