M
Mei
I have some classes at the moment that are initialised with their own
function rather than a constructor and destructor. I wish this case to
be reversed if possible.
For arguments sake (you dont need or want the actual classes here the
shortened ones are long enough):-
class A {
int i;
public:
void init(int ii);
}
class B (
int i;
A a;
public:
void init(int ii,A& aa);
}
A::init(int ii) {
i=ii;
}
B::init(int ii,A& aa){
i=ii;
a=aa;
}
int main() {
A a;
B b;
a.init(1);
b.init(1,a);
}
B is successfully composed into A and both initiate fine. If i
replace the "void init" functions with constructors and deconstructors
like so :-
class A {
int i;
public:
A(int ii);
~A(){};
}
class B (
int i;
A a;
public:
B(int ii,A& aa);
~B(){};
}
A::A(int ii) {
i=ii;
}
B::B(int ii,A& aa){
i=ii;
a=aa;
}
Class B no longer works due to the compiler error "no matching
function for call to `" (I think there should be more to that), From
what i can gather though whats happening is that I am trying to
instantiate class A in the arguments for class B, rather than pass
class A.
What am i doing wrong?
function rather than a constructor and destructor. I wish this case to
be reversed if possible.
For arguments sake (you dont need or want the actual classes here the
shortened ones are long enough):-
class A {
int i;
public:
void init(int ii);
}
class B (
int i;
A a;
public:
void init(int ii,A& aa);
}
A::init(int ii) {
i=ii;
}
B::init(int ii,A& aa){
i=ii;
a=aa;
}
int main() {
A a;
B b;
a.init(1);
b.init(1,a);
}
B is successfully composed into A and both initiate fine. If i
replace the "void init" functions with constructors and deconstructors
like so :-
class A {
int i;
public:
A(int ii);
~A(){};
}
class B (
int i;
A a;
public:
B(int ii,A& aa);
~B(){};
}
A::A(int ii) {
i=ii;
}
B::B(int ii,A& aa){
i=ii;
a=aa;
}
Class B no longer works due to the compiler error "no matching
function for call to `" (I think there should be more to that), From
what i can gather though whats happening is that I am trying to
instantiate class A in the arguments for class B, rather than pass
class A.
What am i doing wrong?