Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer to incomplete class type is not allowed

For some reason I cannot use functions attached to the object I want to use. I added a comment to the line that is not working. As an error I get "Error; pointer to incomplete class type is not allowed" Please help

This is 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 code in wielrenner.h

#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; } 
like image 892
Sharpless512 Avatar asked Aug 19 '12 15:08

Sharpless512


People also ask

What does pointer to incomplete class type mean?

This error usually means that you are trying to follow a pointer to a class, but the compiler did not find the definition of that class (it found a declaration for the class, so it is not considered an unknown symbol, but it did not find a definition, so it is considered an incomplete class).

What is incomplete class type?

An incomplete class declaration is a class declaration that does not define any class members. You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete.

What is do not cast or delete pointers to incomplete classes?

Casting pointers or references to incomplete classes can result in bad addresses. Deleting a pointer to an incomplete class results in undefined behavior if the class has a nontrivial destructor. Doing so can cause program termination, a runtime signal, or resource leaks.


1 Answers

An "incomplete class" is one declared but not defined. E.g.

class Wielrenner; 

as opposed to

class Wielrenner {     /* class members */ }; 

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

like image 161
KRyan Avatar answered Oct 02 '22 12:10

KRyan