trying to Implement a class which takes another class as a parameter, caused to "no matching function for call to myclass(B)" | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

trying to Implement a class which takes another class as a parameter, caused to "no matching function for call to myclass(B)"

the class A is A(int x, B y) and B is B(int z) what is the problem?

16th May 2017, 4:23 PM
arash ardeshiri
arash ardeshiri - avatar
3 Réponses
+ 4
Did you declare class B before class A?
16th May 2017, 4:27 PM
Karl T.
Karl T. - avatar
0
Can you post some code on how you initialize them?
16th May 2017, 4:27 PM
Testing002
0
it's really hard to write code here but it's something like: //A.h: #include "B.h" #ifndef A_H #define A_H Class A { public: A (int , B ); ... private: int x; B y; } //A.cpp: #include "A.h" #include "B.h" #include ... A::A(int xx, B yy) /* Apparently the source of error */ { setx (xx); sety (yy); } //B.h: class B { public : B (int); ... private : int a; } //B.cpp: #include "B.h" B::B (int x) { setx (x); } ... //main: #include "A.h" #include "B.h" #include... int main () { B beta (3); A alpha (2,beta); ... }
16th May 2017, 4:54 PM
arash ardeshiri
arash ardeshiri - avatar