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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:16:25+00:00 2026-06-09T18:16:25+00:00

i got this class to get a list of all derived objects Register.h —————–

  • 0

i got this class to get a list of all derived objects

Register.h
-----------------
class Register {
...
public:

// static object list
static list<Register*> instances;

// default constructor for register object
Register::Register();

// virtual destructor to clean up with subobject destructor first
virtual Register::~Register();

// default methods for this class
static void Register::stop();

Register.cpp
-----------------
#include "Register.h"

// list with all object instances made by this programm
list<Register*> Register::instances;

// default destructor
Register::~Register() {
  list<Register*>::iterator p = find(instances.begin(), instances.end(), this);
  if (p != instances.end()) {
    instances.erase(p);
  }
}

// erase all instances clean up the dish
void Register::stop() {
  // last log message
  Log::write("register cleanup");
  // stops the logging object
  Log::stop();
  // clean up instances
  list<Register*>::iterator iter = instances.begin();
  list<Register*>::iterator end  = instances.end();
  while (iter != end) {
    cout<< endl << (*iter) -> typeName << endl;
    //delete *iter;
  }
  Register::instances.clear();
}

and derived classes

File.h
-----------------
class File : public Register {
...
// default destructor
virtual File::~File(void);
...
}

File.cpp
-----------------
// default destructor
File::~File(void) {
  cout << "file destr";
  this -> deleteFile();
}

Log.h
-----------------
// this class implements a log handler
// (derived from register)
class Log : public File {

public:
  // singelton logging object
  static Log* log;

  // default destructor
  Log::~Log(void);

Log.cpp
-----------------
using namespace std;

// declare pointer for easy logging
Log* Log::log = NULL;

// default destructor
Log::~Log(void) {
cout << "log destr";
}

now i want to delete the whole structure with simply delete the list and the objects in it..

i tried with

 Main.cpp
-----------------
 int main (int argc, char *argv[], char *envp[]) {

   Register::stop();

   return 1;
 }

but the objects are still instanced

i´m out of ideas ^^

kindly..

  • 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-09T18:16:27+00:00Added an answer on June 9, 2026 at 6:16 pm

    Register::instances.clear();

    This clears list of pointers, but doesn’t do anything with objects. You need to remove them yourself before clearing the list, e.g. like this

    for (list<Register *>::iterator it = Register::instances.begin();
         it != Register::instances.end();
         ++it) {
        delete *it;
    }
    Register::instances.clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this class: class Foo { public string Name { get; set; }
ive got this exception. My Object looks like this: @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ObjectDTO
So i got a class like this: class Db { protected static $dbh =
I've got essentially an elaborate wrapper around a list of dictionaries: class Wrapper(object): def
i got this code off the internet, i suppose to get a list of
Assuming that I have objects similar to this: public class User { public int
I´ve got this CRac class and it´s giving me some problems with its members.
What the right way to interrupt executor's thread? I've got this: Thread class with
I got this simple cache class setted up as a library in the Codeigniter:
I got a scenario like this Class Parent { Property A; } Class A

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.