Klassen über mehrere Dateien in C ++
Ich bin fast zu 100% sicher, dass ich in beiden Klassen die richtige Syntax habe, es werden jedoch die folgenden Fehler angezeigt:
Für CShape.cpp - "Fehler C2011: 'CShape': 'Klasse' Typneudefinition" Für CCircle.cpp - "Fehler CS2504: 'CShape': Basisklasse undefiniert"
Hier ist der vollständige Code für CShape.cpp
#include <iostream>
using namespace std;
class CShape
{
protected:
float area;
virtual void calcArea();
public:
float getArea()
{
return area;
}
}
Und hier ist der Code für CCircle.cpp
#include <iostream>
#include "CShape.cpp"
#define _USE_MATH_DEFINES
#include "math.h"
using namespace std;
class CCircle : public CShape
{
protected:
int centerX;
int centerY;
float radius;
void calcArea()
{
area = M_PI * (radius * radius);
}
public:
CCircle(int pCenterX, int pCenterY, float pRadius)
{
centerX = pCenterX;
centerY = pCenterY;
radius = pRadius;
}
float getRadius()
{
return radius;
}
}
Wie Sie sehen, ist CShape die Basisklasse, von der CCircle erben soll. Ich bin ziemlich neu in C ++, daher kann es sein, dass die Dateistrukturen falsch sind (möglicherweise befindet sich die Basis in einer Header-Datei?), Wenn so etwas wichtig ist.