mardi 3 janvier 2017

'Class': no appropriate default constructor available

I got class A and class B, class A has a variable of class B and class B wants a reference to class A. Here is what it looks like:

A.cpp:

#include "A.h"

A::A(Graph* graph)
: _graph(graph)
, _b(*this)
{

}

A.h:

#include "../IGameObject.h"
#include "../Domain/Graph.h"
#include "B.h"

class Graph;

class A: public IGameObject 
{
    friend class B;
public:
    A(Graph* graph);
    ~A();

    B _b;

private: 
    Graph* _graph;
};

B.cpp

#include "B.h"
#include "A.h" 

B::B(A& context)
: _a(context)
{
}

B.h:

#include "../IGameObject.h"
#include <vector>

using std::vector;

class A;

class B: public IGameObject {
public:
    B(A& context);

private:
    A& _a;

Now the problem is in the file A.cpp it gives the error "'A': no appropriate default constructor available" on line ", _b(*this)"

Aucun commentaire:

Enregistrer un commentaire