What could be wrong here? Multiple Inheritance

I wrote the following classes, but there is syntax errors there, but I cannot figure out why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class cd_c {
public:
	static physics_c phy;//physics_c is a defined class
};


class cPoint_c:public point_c, public cd_c {//error messsage:invalid use of incomplete type ‘class point_c’
public:
	cellType_e T;

	cPoint_c(const numeric_t & xV=0, const numeric_t & yV=0
		   , const cellType_e & tv=fCell)
	: point_c(xV, yV)//point_c(x,y) constructor is defined, but there is error message:type ‘point_c’ is not a direct base of ‘cPoint_c’
	, T(tv) {}

	virtual ~cPoint_c()=default;
};

what is an incomplete type? I cannot have a type which only has static members?
please explain what is the problem here? Thanks
Last edited on
A class that has been declared but not defined (class point_c above) is an incomplete type.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class point_c ; // point_c is an incomplete type here

class A : public point_c  // *** error: the base class can't be of an an incomplete type
{
     //...
};

class point_c 
{
     // ...
}; // point_c is now a complete type (the class has been defined) 

class B : public point_c  // fine
{
     //...
};
1
2
3
4
class cd_c {
public:
	static physics_c phy;
};


this is the definition of cd_c, doesn't this one count?

point_c is defined in another file, and that head file is included, there should be no problem???
Last edited on
> point_c is defined in another file, and that head file is included, there should be no problem???

There should be no problem.

Make sure that the definition of point_c is complete.
(#include the header containing point_c in an otherwise empty .cpp file and try to compile it.)

And verify that the #include guard is unique.
Thanks, JLBorges! Now that comes to here, let me ask you a question about class declaration

Firstly, I did these:

in file A.h:
1
2
3
4
5
6
#ifndef A_H_
#define A_H_
class point_c {
//definition here
};
#endif 


in file B.h:
1
2
3
4
5
6
7
8
9
10
11
#ifndef A_H_
#define A_H_

#inculde "C.h";//following showed pore_c, so C.h should be included

class cell_c:public point_c {
public:
    //definition here
    vector<pore_c *> pv;
}
#endif 

in file C.h:
1
2
3
4
5
6
7
8
9
10
#ifndef A_H_
#define A_H_

#include "B.h";//following showed cell_c, so C.h should be included
class pore_c:cell_c {
public:
    //definition here
    vector<cell_c*> cv;
}
#endif 


Because of this cross include, there will be problems. So I changed my stratge. I declared all class in a file firstly, and let all three definition header files to include it.

like this:

in file D.h:

1
2
3
class point_c;
class cell_c;
class pore_c;


and then for example

in file B.h:
1
2
3
4
5
#include "D.h"

class cell_c {
vector<pore_c *> pv;
}


head guard are added for all three files. Everything looks good.

But Now I suddenly realized, I need all classes share a static member.

so I declared this cd_c in D.h.

and defined it in B.h

1
2
3
4
class cd_c {
public:
	static physics_c phy;//physics_c is a defined class
};



1
2
3
4
5
6
7
8
9
10
11
class cell_c:public point_c, public cd_c {//error messsage:invalid use of incomplete type ‘class point_c’
public:
	cellType_e T;

	cell_c(const numeric_t & xV=0, const numeric_t & yV=0
		   , const cellType_e & tv=fCell)
	: point_c(xV, yV)//point_c(x,y) constructor is defined, but there is error message:type ‘point_c’ is not a direct base of ‘cell_c’
	, T(tv) {}

	virtual ~cell_c()=default;
};


now here comes the problem with which I initiate this question. The definition of point_c is complete I already tested. I guess the problem is in this multi inheritance. What could be worng?

Thanks.
Last edited on
Er, those include guards aren't unique. All of them are using A_H_, is that a typo?

You have a circular inclusion error in B.h and C.h, you can't have them both include each other like that. See: http://www.cplusplus.com/forum/articles/10627/
That is a typo, haha, thanks
physics_c.h
1
2
3
4
5
6
7
8
#ifndef PHYSICS_C_H_INCLUDED
#define PHYSICS_C_H_INCLUDED

class physics_c {
    // ...
};

#endif // PHYSICS_C_H_INCLUDED 


point_c.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef POINT_C_H_INCLUDED
#define POINT_C_H_INCLUDED

#include "physics_c.h"

class point_c  {
    // ...
    protected: static physics_c phy ; // shared by all classes in the hierarchy
};

#endif // POINT_C_H_INCLUDED 


cell_c.h
1
2
3
4
5
6
7
8
9
10
#ifndef CELL_C_H_INCLUDED
#define CELL_C_H_INCLUDED

#include "point_c.h"

class cell_c : public point_c {
    // ...
};

#endif // CELL_C_H_INCLUDED 




pore_c.h
1
2
3
4
5
6
7
8
9
10
#ifndef PORE_C_H_INCLUDED
#define PORE_C_H_INCLUDED

#include "cell_c.h"

class pore_c : cell_c {
    // ...
};

#endif // PORE_C_H_INCLUDED 
Thanks, but this doesn't answer my question.

Topic archived. No new replies allowed.