i want to frd the MainControl with the derived class food


objects.h (abstract base)

#include "maincontrol.h"

class objects
{...};


food.h (derived)

#include "objects.h"
using namespace std;

class food: public objects 
{...};

maincontrol.h

class objects;
class food;
class MainControl
{
public:
friend objects;
friend food;
...
};

MainControl::MainControl(char x)
{
switch(x)
{
case 'f': pointer = new food(...);break;
...
}
}

error C2514: 'food' : class has no constructors (line 15)
see declaration of 'food' (line 7)

is the error caused by friending MainControl with a derived class?

class objects;
class food;
class MainControl
{
  public:
  friend class objects;
  friend class food;
  // ...
};

> error C2514: 'food' : class has no constructors (line 15)
> see declaration of 'food' (line 7)
> is the error caused by friending MainControl with a derived class?
no.
class food has been declared, but not defined.
you need to #include "food.h"

> error C2514: 'food' : class has no constructors (line 15)
> see declaration of 'food' (line 7)
> is the error caused by friending MainControl with a derived class?
no.
class food has been declared, but not defined.
you need to #include "food.h"

thanks
it's the way that I've been including files which has caused the trouble
i've found the solution

class A.h

class B;
class A:
{
public:
friend B;
};

include class B.h in class A.cpp

class B.h

class A;
class B:
{
public:
friend A;
};

include class A.h in class B.cpp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.