C++ Classes Inheritance

Hello!, having some problem in writing code with multi inheritance:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  in classA.h
class A declaration,
same goes to classB.h - classH.h
in class B.cpp - H.cpp
class B{
public:
B(); //constructor without parameters
B(param_a, ... param_n){
variable_a,
..
variable_n} //constructor with parameters
in class A.cpp
class A {
public:
A();
A(param_A, B(param),..H(param)){
variable A}
in main.cpp
A a;
a.A(param);
A new_A;
new_A.A(param)


//I'm calling constructors with parameters from others classes B-H to constructor with parameters in class A. What do I need to do, rewrite or smth else for this to work as it should?
Generally speaking I don't think you would try to call a constructor directly, although I think there is some more technical method of doing so in some instances.

See the the question on this page, especially the last post:
http://www.cplusplus.com/forum/beginner/11109/
you talk about inheritance, yet nothing in your "code" shows inheritance
your code is not code, but some kind of description
then you want "this to work as it should" be never say what is "this" nor say what doesn't work (error messages)

not sure what you expect us to do.
http://www.cplusplus.com/doc/tutorial/inheritance/

Your code contains nothing of inheritance. It's just a bunch of psuedocode of classes.
Thanks to "Cheddar99" & "fiji885", especially "fiji885"! Your link is the thing I needed, but here comes another question. Based on multiple inheritance code I presume that I need to call derived constructor each time i call base constructor for inheritance to work?
something like:
1
2
3
4
5
6
class A:public B,...public N{
}
A(param_a, param_n,):B(param_a,param_n){}
A(param_a,param_n):C(param_a,param_n){}
...
A(param_a,param_n):N(param_a,param_n

it seems like code is a little too overwritten(big) and slow to read,
or maybe it is possible to make it smth like this:
 
A(param_a,param_n):B(param_a,param_n),...N(param_a,param_n){}???

it's just that i need to write derived constructor that accepts parameters of 10+ basic constructors with 10+ parameters each and most possibly simplify it....

Thank You again guys/girls...
Last edited on
Lines 3-6: It appears you're implying all the constructors all have the same argument lists.
You can't do that. When you call A's constructor, the compiler must be able to distinguish the calls. BTW, line 3 has an extraneous comma.

If you want to initialize multiple base classes, the syntax is
1
2
3
4
5
6
class A:public B,...public N : 
    B(param_a, ... param_n),
    C(param_a, ... param_n),
...
    N(param_a, ... param_n
{}


If all the parameters are always the same, you might consider placing them in a struct.
1
2
3
4
5
6
7
8
9
10
11
12
struct param_block 
{  param_a  a;
   param_b  b;
...
   param_n  n;
};

class A : public param_block  //Inherits
{  
public: 
    A (const param_block & pb);
};


Invocation:
1
2
  param_block  pb;  // Initialize somehow
  A a (pb);

Last edited on
"AbstractionAnon" Thank You I'll try this method, but it's not the thing I need...
Topic archived. No new replies allowed.