I have a class B that creates an object of a class A and calls a method of the object.
a.h
#ifndef A_H
#define A_H
class A
{
public:
A(int);
void function();
};
#endif // A_H
a.cpp
#include "a.h"
A::A(int x)
{
}
void A::function(){
//Do something.
}
b.h
#ifndef B_H
#define B_H
#include <QVector>
#include <a.h>
class B
{
public:
B(int);
QVector<A> list;
};
#endif // B_H
b.cpp
#include "b.h"
B::B(int y)
{
list.append(A(y));
list[0].function();
}
The problem is that this does not compile. It returns "no matching function to call 'A:A()'". I know that this can be solved with a forward declaration but this does not work here since I want to call the function "function". I also do not want to include the whole class A in the class B.
See Question&Answers more detail:os