dimanche 10 novembre 2019

error: unknown type name in a header class containing multiple classes

I'm new in C++ and I got this message error:

g++ -Wall -c -o inventaire.o inventaire.cpp In file included from inventaire.cpp:11: ./inventaire.h:57:11: error: unknown type name 'IngredientsRecette'; did you mean 'ListeIngredientsRecette'? Liste listeIngRecette; ^~~~~~~~~~~~~~~~~~ ListeIngredientsRecette ./inventaire.h:44:7: note: 'ListeIngredientsRecette' declared here class ListeIngredientsRecette{ ^ 1 error generated. make: *** [inventaire.o] Error 1

Explanation

It's not because of the compiler because without the declaration of "Liste listeIngRecette; " It's working without any error message. I'm using a makefile. First time posting so tell me if I'm doing wrong so that I can improve. Yes I know it's French...


Here is my header file:

#if !defined(_INVENTAIRE__H_)
#define _INVENTAIRE__H_

#include <iostream>
#include <string>
#include "date.h"
#include "liste.h"

using namespace std;

....



class ListeIngredientsRecette{
  public:
    ListeIngredientsRecette(){}  
    ListeIngredientsRecette& operator+=(const ListeIngredientsRecette& liste);
    ListeIngredientsRecette& operator*=(int quantite);

  private:

    Liste<IngredientsRecette> listeIngRecette; 
  friend std::istream& operator >> (std::istream&, ListeIngredientsRecette&);
  friend std::ostream& operator << (std::ostream&, const Date& date);
  friend class ListeIngredientsRecette;
  friend class IngredientsRecette;
  friend class IngredientInventaire;
  friend class Inventaire;
};

class IngredientsRecette{
  public:
      IngredientsRecette() 
        : nom(""), quantite(0) {}

      IngredientsRecette(const string& nomRecette, const int & qt) 
        : nom(nomRecette), quantite(qt) {}

      string nom; 
      int quantite; 
  private:
  friend class ListeIngredientsRecette;
  friend class IngredientsRecette;
  friend class IngredientInventaire;
  friend class Inventaire; 
};

Aucun commentaire:

Enregistrer un commentaire