Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Stabilizing the error with the best answers: pointer to incomplete class type is not allowed
Next
Answered
Hugo Ricard
  • 22
Hugo Ricard
Asked: May 18, 20222022-05-18T10:10:53+00:00 2022-05-18T10:10:53+00:00In: cpp

Stabilizing the error with the best answers: pointer to incomplete class type is not allowed

  • 22

. Advertisement .

..3..

. Advertisement .

..4..

I’m trying to run a new project. I do a couple of things like this:

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++;
  } 
#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_ */
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;
 }

But in my program, I am getting the warning:

Error; pointer to incomplete class type is not allowed

Can someone explain why the “ pointer to incomplete class type is not allowed” issue happened? Where have I gone wrong? Thank you!

pointer to incomplete class type
  • 2 2 Answers
  • 34 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    hdtutoria Expert
    2022-06-05T12:29:52+00:00Added an answer on June 5, 2022 at 12:29 pm

    The cause: This error happens perhaps due to an “incomplete class” is one declared but not defined.

    The solution: To solve this problem, you need to #include "wielrenner.h" in dokter.ccp, because #include "wielrenner.h" is required in dokter.ccp in order for it to be aware of the class’s details. Dokter.h appears to just have class Wielrenner in it, resulting in the incomplete class error.
    Example:

    class Wielrenner;

    in contrast to

    class Wielrenner
    {
        /* class members */
    };
    • 8
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Nathan de Oliveira
    2022-05-25T20:11:55+00:00Added an answer on May 25, 2022 at 8:11 pm

    You should also be on the lookout for:

    Your class can be defined as a typedef

    typedef struct myclass { };

    If you refer to it struct myclass elsewhere, you will get Incomplete Type errors all over. Sometimes it’s a mistake to forget that the class/struct typedef’ed. If this is the case, you can remove “struct”

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

    Instead use…

    mystruct *myvar = value;

    Common mistake.

    • 23
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.