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?
3 odpowiedzi
+ 4
Did you declare class B before class A?
0
Can you post some code on how you initialize them?
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);
...
}