Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: forward declaration of struct

I'm receiving the error:

proprietario.cpp:36: error: invalid use of incomplete type ‘struct Motocicleta’
proprietario.h:12: error: forward declaration of ‘struct Motocicleta’

Motocicleta.h:

#ifndef __MOTOCICLETA__
#define __MOTOCICLETA__
#include <iostream>
#include "veiculo.h"
#include "proprietario.h"
using namespace std;
class Proprietario;
class Motocicleta:public Veiculo{

public:
  Motocicleta(int nPassageiros, string modelo, string placa, int aFabricacao, Proprietario* pai, int nRodas, int aro);
  ~Motocicleta();
  Motocicleta (const Motocicleta& source);
  Motocicleta& operator= (const Motocicleta& source);

  string toString();

};                     
#endif

Proprietario.h

#ifndef __PROPRIETARIO__
#define __PROPRIETARIO__

#include <iostream>
#include "motocicleta.h"
#include "caminhao.h"
#include "carreta.h"
#include "carro.h"

using namespace std;

class Carro;
class Carreta;
class Caminhao;
class Motocicleta;

class Proprietario{
protected:
  string nome;
  string cpf;
  Motocicleta* mMoto;
  Caminhao* mCaminhao;
  Carreta* mCarreta;
  Carro* mCarro;
};

Veiculo.h:

#ifndef __VEICULO__
#define __VEICULO__
#include <iostream>
#include "proprietario.h"
#include "roda.h"
#include "motor.h"

using namespace std;
class Motor;
class Proprietario;
class Veiculo{
protected:
  int nPassageiros;
  string modelo;
  string placa;
  int aFabricacao;
  Proprietario* pai;
  Roda* rodas;
  Motor* mMotor;
  int nRodas;
  };

I removed the methods, because if i added those the question will be to long, sorry, the code is in PT-BR. I saw that the problem is usually is forward declaration. But i cannot find out the problem, i looked in so many forums but i cannot find out the problem..

Someone can help me?

Need any other part of the code?

like image 785
Lefsler Avatar asked Mar 23 '12 13:03

Lefsler


1 Answers

In Proprietario.cpp on line 36 you do something with class Motocicleta, without including full class declaration first (you only have a forward declaration).

like image 133
dbrank0 Avatar answered Sep 21 '22 16:09

dbrank0