Pointer to an incomplete class type is invalid

For some reason, I cannot use the functions associated with the object I want to use. I added a comment to a line that doesn't work. As an error, I get the error "Error: pointer to an incomplete class type." Please, help

This is the code in dokter.ccp

int counter = 0; for (list<Wielrenner*>::iterator it = wielrenners.begin(); it != wielrenners.end(); it++){ Wielrenner* wielrennerOB = *it; cout << "\nID: " << counter; cout << "List size: " << persons.size() << endl; wielrennerOB->print(); // This is not working counter++; } 

This is the code in the wielrenner.h file

 #ifndef WIELRENNER_H_ #define WIELRENNER_H_ //#include <fstream> #include "persoon.h" #include "Onderzoek.h" class Wielrenner : public Persoon { public: Wielrenner(string, string, Adres, string, Datum, Datum, string, int, float, float, float,list<Onderzoek>* ); ~Wielrenner(void); int getLengte() const; float getGewicht() const; float getVo2max() const; float getMaxVermogen() const; list<Onderzoek> getOnderzoekenList(); void setLengte(int); void setGewicht(float); void setVo2max(float); void setMaxVermogen(float); void voegOnderzoekToeList(Onderzoek); void showOnderzoeksList(); void setOnderzoeksLijst(list<Onderzoek>&); void print(); void printFile(ofstream&); private: int lengte; float gewicht; float vo2max; float maxVermogen; list<Onderzoek> onderzoeken; }; #endif /* WIELRENNER_H_ */ 

code in wielrenner.CCP

 using namespace std; #include <string> #include "Wielrenner.h" /* #include "Onderzoek.h" */ Wielrenner::Wielrenner(string voornaam, string achternaam, Adres adres, string telefoon, Datum datumInDienst, Datum geboorteDatum, string persoonType, int lengte, float gewicht, float vo2max, float maxVermogen,list<Onderzoek>* onderzoeken) : lengte(lengte), gewicht(gewicht), vo2max(vo2max), maxVermogen(maxVermogen), Persoon(voornaam, achternaam, adres, telefoon, datumInDienst, geboorteDatum, persoonType) { } Wielrenner::~Wielrenner(void) { } //setten van gegevens void Wielrenner::setLengte(int newLengte){ lengte = newLengte; } void Wielrenner::setGewicht(float newGewicht){ gewicht = newGewicht; } void Wielrenner::setVo2max(float newVo2max){ vo2max = newVo2max; } void Wielrenner::setMaxVermogen(float newMaxVermogen){ maxVermogen = newMaxVermogen; } void Wielrenner::voegOnderzoekToeList(Onderzoek newOnderzoek){ onderzoeken.push_back(newOnderzoek); } void Wielrenner::showOnderzoeksList(){ int teller=0; for (list<Onderzoek>::iterator it = onderzoeken.begin(); it != onderzoeken.end(); it++){ Onderzoek onderzoekOB = *it; cout << teller << " - "; onderzoekOB.print(); teller++; } } void Wielrenner::setOnderzoeksLijst(list<Onderzoek>& newOnderzoeksLijst){ onderzoeken = newOnderzoeksLijst; } void Wielrenner::print(){ cout << "(" << persoonID << ") Persoon: " << endl; cout << persoonType << endl; cout << voornaam << " " << achternaam << endl; adres.print(); cout << telefoon << endl; cout << "Datum in dienst: "; datumInDienst.print(); cout << "Geboortedatum: "; geboorteDatum.print(); cout << "> Extra wielrenner gegevens: " << endl; cout << "Lengte: " << lengte << endl; cout << "Gewicht: " << gewicht << endl; cout << "vo2max: " << vo2max << endl; cout << "maxVermogen: " << maxVermogen << endl; } void Wielrenner::printFile(ofstream &myfile){ myfile << persoonID << "\n"; myfile << persoonType << "\n"; myfile << voornaam << " " << achternaam << "\n"; adres.printFile(myfile); myfile << telefoon << "\n"; datumInDienst.printFile(myfile); geboorteDatum.printFile(myfile); myfile << lengte << "\n"; myfile << gewicht << "\n"; myfile << vo2max << "\n"; myfile << maxVermogen << "\n"; } // returnen van gegevens int Wielrenner::getLengte() const{ return lengte; } float Wielrenner::getGewicht() const{ return gewicht; } float Wielrenner::getVo2max() const{ return vo2max; } float Wielrenner::getMaxVermogen() const{ return maxVermogen; } list<Onderzoek> Wielrenner::getOnderzoekenList(){ return onderzoeken; } 
+48
c ++ iterator list pointers class
Aug 19 '12 at 15:26
source share
5 answers

An "incomplete class" is declared, but not defined. For example.

 class Wielrenner; 

Unlike

 class Wielrenner { /* class members */ }; 

You need #include "wielrenner.h" in dokter.ccp

+92
Aug 19 '12 at 15:30
source share

One thing to check ...

If your class is defined as typedef:

 typedef struct myclass { }; 

Then you try to refer to it as struct myclass elsewhere, you will get incomplete type errors on the left and right. Sometimes it is a mistake to forget that the class / structure was typedef'ed. If this is the case, remove the "struct" from:

 typedef struct mystruct {}... struct mystruct *myvar = value; 

Use ... instead

 mystruct *myvar = value; 

Common mistake.

+6
Jan 19 '16 at 17:01
source share

You get this error when declaring a direct link inside the wrong namespace, thereby declaring a new type without defining it. For example:

 namespace X { namespace Y { class A; void func(A* a) { ... } // incomplete type here! } } 

... but in class A the following was defined:

 namespace X { class A { ... }; } 

So A was defined as X::A , but I used it as X::Y::A

The fix, obviously, is to move the direct link to the appropriate place:

 namespace X { class A; namespace Y { void func(X::A* a) { ... } // Now accurately referencing the class`enter code here` } } 
+5
Jun 01 '17 at 16:43 on
source share

I ran into the same problem and solved it by checking out my #includes. If you are using QKeyEvent, you must make sure that you also enable it.

I had a class like this, and my error came up while working with the "event" in the .cpp file.

myfile.h

  #include <QKeyEvent> // adding this import solved the problem. class MyClass : public QWidget { Q_OBJECT public: MyClass(QWidget* parent = 0); virtual ~QmitkHelpOverlay(); protected: virtual void keyPressEvent(QKeyEvent* event); }; 
0
Dec 02 '15 at 12:17
source share

Check if you are short of imports.

0
Jul 09 '19 at 8:29
source share