[c++] 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;
}

This question is related to c++ list class pointers iterator

The answer is


I came accross the same problem and solved it by checking my #includes. If you use QKeyEvent you have to make sure that you also include it.

I had a class like this and my error appeared when working with "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);
    };

Check out if you are missing some import.


One thing to check for...

If your class is defined as a typedef:

typedef struct myclass { };

Then you try to refer to it as struct myclass anywhere else, you'll get Incomplete Type errors left and right. It's sometimes a mistake to forget the class/struct was typedef'ed. If that's the case, remove "struct" from:

typedef struct mystruct {}...

struct mystruct *myvar = value;

Instead use...

mystruct *myvar = value;

Common mistake.


You get this error when declaring a forward reference inside the wrong namespace thus 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 was defined like this:

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

Thus, A was defined as X::A, but I was using it as X::Y::A.

The fix obviously is to move the forward reference to its proper place like so:

namespace X
{
  class A;
  namespace Y
  {
    void func(X::A* a) { ... } // Now accurately referencing the class`enter code here`
  }
}

Examples related to c++

Method Call Chaining; returning a pointer vs a reference? How can I tell if an algorithm is efficient? Difference between opening a file in binary vs text How can compare-and-swap be used for a wait-free mutual exclusion for any shared data structure? Install Qt on Ubuntu #include errors detected in vscode Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio 2017 errors on standard headers How do I check if a Key is pressed on C++

Examples related to list

Convert List to Pandas Dataframe Column Python find elements in one list that are not in the other Sorting a list with stream.sorted() in Java Python Loop: List Index Out of Range How to combine two lists in R How do I multiply each element in a list by a number? Save a list to a .txt file The most efficient way to remove first N elements in a list? TypeError: list indices must be integers or slices, not str Parse JSON String into List<string>

Examples related to class

String method cannot be found in a main class method Class constructor type in typescript? ReactJS - Call One Component Method From Another Component How do I declare a model class in my Angular 2 component using TypeScript? When to use Interface and Model in TypeScript / Angular Swift Error: Editor placeholder in source file Declaring static constants in ES6 classes? Creating a static class with no instances In R, dealing with Error: ggplot2 doesn't know how to deal with data of class numeric Static vs class functions/variables in Swift classes?

Examples related to pointers

Method Call Chaining; returning a pointer vs a reference? lvalue required as left operand of assignment error when using C++ Error: stray '\240' in program Reference to non-static member function must be called How to convert const char* to char* in C? Why should I use a pointer rather than the object itself? Function stoi not declared C pointers and arrays: [Warning] assignment makes pointer from integer without a cast Constant pointer vs Pointer to constant How to get the real and total length of char * (char array)?

Examples related to iterator

Iterating over Typescript Map Update row values where certain condition is met in pandas How to iterate (keys, values) in JavaScript? How to convert an iterator to a stream? How to iterate through a list of objects in C++ How to avoid "ConcurrentModificationException" while removing elements from `ArrayList` while iterating it? How to read one single line of csv data in Python? 'numpy.float64' object is not iterable Python list iterator behavior and next(iterator) python JSON only get keys in first level