Inheritance across multiple files

I'm almost 100% sure I have the syntax right in both of these classes, however I'm getting the following errors:

For CShape.cpp - "error C2011: 'CShape' : 'class' type redefinition"
For CCircle.cpp - "error CS2504: 'CShape': base class undefined"

Here is the full code for CShape.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    #include <iostream>
    using namespace std;

    class CShape
    {
    protected:
	    float area;
	    virtual void calcArea();
    public:
	    float getArea()
	    {
		    return area;
	    }
    }

And here is the code for CCircle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    #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;
	    }
    }

As you can see, CShape is the base class that CCircle is suppsoed to inherit from. I'm pretty new to C++, so I could have the file structures wrong (maybe the base is supposed to be in a header file?), if something like that matters.
You are right that you need to use header files. You can never #include a .cpp file.

If you don't know much about them there are several articles around that explain header files in detail.
http://www.cplusplus.com/forum/articles/10627/
Last edited on
Besides not using header files, you're also missing a semicolon at the end of the class declarations.
Topic archived. No new replies allowed.