2

I have the following files and I don't understand why it doesn't work and why I obtain

'Pixel' was not declared in this scope

Here the header:

#ifndef TABRESULTATS_H #define TABRESULTATS_H #include "Ligne.h" #include <iostream> #include <cmath> #include "Pixel.h" #include <vector> using namespace std; class Tableresultats { public: Tableresultats(vector<Pixel> pixels); Tableresultats(vector<Pixel> pixels, int seuil); Tableresultats(); virtual ~Tableresultats(); protected: private: vector<int> m_debut; vector<int> m_duree; vector<int> m_valeurMax; int m_seuilGris; }; #endif // TABRESULTATS_H 

The .cpp:

#include "Tableresultats.h" #include "Ligne.h" #include <iostream> #include <cmath> #include "Pixel.h" #include <vector> using namespace std; int vmaxTemp; int dureeTemp; Tableresultats::Tableresultats(); { m_seuilGris=180; //valeur par defaut vector<int> debut(); vector<int> duree(); vector<int> vmax(); //ctor } Tableresultats::Tablesreultats(vector<Pixel> pixels); { // ... } Tableresultats::Tableresultats(vector<Pixel> pixels, int seuil); { m_seuilGris=seuil; //valeur par defaut // ... } Tableresultats::~Tableresultats() { } 

And my class pixel:

#ifndef PIXEL_H #define PIXEL_H #include <iostream> #include "Tableresultats.h" using namespace std; class Pixel { public: ... protected: private: int m_couleurRGB[3]; //La couleur du pixel int m_niveauGris; //Niveau gris int m_posX; //reference X int m_posY; //reference Y }; #endif // PIXEL_H 

I have other files but I don't understand why I have this problem:

Pixel was not declared in this scope, line 16 Tableresultats.h header

if I have declared #include <vector> and #include "Pixel.h"

1 Answer 1

4

You have a circular dependency between Tableresultats.h and Pixel.h (they include each other).

You'll have to resolve that by making proper use of forward declarations.

Or remove one of those includes if possible (from what you posted of Pixel.h, it doesn't look like it needs the include for Tableresultats.h).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.