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 a question.

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9276119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:45:40+00:00 2026-06-18T16:45:40+00:00

I’m trying to set up a basic entity/object management system, and I have two

  • 0

I’m trying to set up a basic entity/object management system, and I have two classes, one for being a base-class for entities from which to inherit, and one to manage and control them all.

This is the source code I’m trying to use:

#include <iostream>
#define MAX_ENTS 400
class EFentity;
class EFiterator;
class EFentity {
     public:
          EFentity();
          virtual bool step();
          virtual void create(EFiterator*,int);
          virtual void destroy();
     private:
          int holder_id;
          EFiterator* holder;
};
EFentity::EFentity(void) {
     //    add base entity stuff
}
void EFentity::destroy() {
     holder->ents[holder_id]=NULL;
     std::cout << "destroying object id "<<holder_id;
     delete this;
}
void EFentity::create(EFiterator* h,int pos) {
     holder=h;
     holder_id=pos;
}
bool EFentity::step() {
     return false;
}
class EFiterator {
public:
     EFentity* ents[MAX_ENTS];
     int e_size;
     EFiterator();
     void push(EFentity* e);
     void update();
};
EFiterator::EFiterator() {
     e_size=0;
}
void EFiterator::update() {
     for(int i=0;i<e_size;i++) {
          if (!ents[i]->step()) {
               std::cout << "entity id "<< i<<" generated a fault!\n";
          } else std::cout << "entity id "<<i<<" passed step test.\n";
     }
}
void EFiterator::push(EFentity* e) {
     ents[e_size]=e;
     e->create(this,e_size++);
}
int main() {
     EFiterator main_iterator;
     main_iterator.push(new EFentity());
     main_iterator.update();
     std::cin.get();
     return 0;
}

This code obviously doesn’t compile, and here are the errors:

In member function `virtual void EFentity::destroy()':

[20] invalid use of undefined type `struct EFiterator' 
[5] forward declaration of `struct EFiterator'

I have seen problems like this on SO before, but they did not require access to member variables and functions of the other class, so it could be easily solved with a pointer.

I think this can be solved by having a prototyped function to access the array inside of EFiterator, but is there a way to do this smoothly with some tricky class manipulation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:45:41+00:00Added an answer on June 18, 2026 at 4:45 pm

    EFentity::destroy() needs know concrete type of EFiterator when it calls

     holder->ents[holder_id]=NULL;
    

    Put EFentity::destroy() after EFiterator definition should resolve the problem, for example, put it after EFiterator

    void EFiterator::push(EFentity* e) {
         ents[e_size]=e;
         e->create(this,e_size++);
    }
    
    void EFentity::destroy() {
         holder->ents[holder_id]=NULL;
         std::cout << "destroying object id "<<holder_id;
         delete this;
    }
    

    Normally forward declare types in header file and include concrete type in .cpp file, which breaks circular include issue.

    EFentity.h

    class EFiterator;
    class EFentity {
         public:
              EFentity();
              virtual bool step();
              virtual void create(EFiterator*,int);
              virtual void destroy();
         private:
              int holder_id;
              EFiterator* holder;
    };
    

    EFentity.cpp

    #include "EFiterator.h"
    
    EFentity::EFentity(void) {
         //    add base entity stuff
    }
    void EFentity::destroy() {
         holder->ents[holder_id]=NULL;
         std::cout << "destroying object id "<<holder_id;
         delete this;
    }
    void EFentity::create(EFiterator* h,int pos) {
         holder=h;
         holder_id=pos;
    }
    bool EFentity::step() {
         return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.