Есть два класса c1 и c2 У каждого класса конструктор с параметром. Класс c1 является членом класса c2.
Вот код.
class c1{
int v;
public:
c1(int n);// конструктор класса c1
};
c1::c1(int n){
v=n;
printf("Constructior c1.\n");
}
class c2{
int v;
public:
c2(int n); // конструктор класса c2
c1 e1;
};
c2::c2(int n){
v=n;
e1.c1(n); //пытаюсь вызвать конструктор класса c1, но не выходит
printf("Constructior c2\n");
}
int main(int argc,char **argv){
c2 e2(5);
}
test.cpp: In constructor ‘c2::c2(int)’:
test.cpp:29: error: no matching function for call to ‘c1::c1()’
test.cpp:17: note: candidates are: c1::c1(int)
test.cpp:12: note: c1::c1(const c1&)
test.cpp:31: error: invalid use of ‘class c1’