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 7509103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:48:29+00:00 2026-05-29T22:48:29+00:00

What I am trying to do is create a base class, for which anything

  • 0

What I am trying to do is create a base class, for which anything derived from it will automatically be registered with another class, eg:

class System;
class Object
{
public:
    Object()
    {
        System sys;
        sys.AddObject(this);
    }
    virtual ~Object()
    {
        System sys;
        sys.RemoveObject(this);
    }
};
class System
{
public:
    // Some other processing function which operates on all things derived
    // from Object at one time.
    void ProcessAllObjectsInExistence();

    void AddObject(Object *o)
    {
        list.push_back(o);
    }
    void RemoveObject(Object *o)
    {
        std::vector<Object *>::iterator i = find(list.begin(), list.end(), o);
        if (*i != list.end()) list.erase(i);
    }
private:
    static std::vector<Object *> list;
};

Is this legal and defined? The reason why I am asking is because I am getting some funny errors after reading and writing to the data members of Object (not shown here) from inside ProcessAllObjectsInExistence().

i.e. for a single Object before I call System.ProcessAllObjectsInExistence() the members are 0 and 100, and then the first line inside ProcessAllObjectsInExistence() is a debugging line which prints the members and displays 0 and 0. painful ><

  • 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-05-29T22:48:30+00:00Added an answer on May 29, 2026 at 10:48 pm

    It is perfectly valid to refer to this inside a Base class.
    However, calling virtual methods(if you have any) inside the Base class won’t actually work the way you think it should.

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

Sidebar

Related Questions

I'm trying to create a class that serves as a base object, which will
Trying to create a base class from which I can derive different types. What's
I am trying to create a class in VB.NET which inherits a base abstract
I'm trying to create a Quicksort base class using VB.NET, taking it an array
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to create a food ordering application. It will recieve menu data from
I'm trying to serialize a class that inherits from a base class that implements
I'm trying to create a base class that provides a good amount of re-usable
I am trying to create a base class that is a wrapper around std::array
Hi I am wanting to create a base class to inherit from but I

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.