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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:21:26+00:00 2026-05-28T13:21:26+00:00

I have written a class (AbcdBase) which holds several static objects, these include maps

  • 0

I have written a class (AbcdBase) which holds several static objects, these include maps and a few static objects that act as “helper tools” such as plotting helper functions, objects which store constants for making tables and so on.

Separately I have other classes (DataSample and DoABCD) that need access to those static members, the twist is that DoABCD creates several instances of DataSample. What would be the correct way of coding this? Having both DataSample and DoABCD be derived classes of AbcdBase doesn’t seem like the correct way (and I get Seg violations when I do that).

class AbcdBase {

private:
    int init();
    int status;

public:

    static SampleAggregator* SampleAggregatorInst;
    static PlotHelper* PlotHelperInst;
    static DataSampleConst* DataSetMap;
    static DataSampleConst::SampleDict* ListOfSamples;
    static std::vector<std::string> ListOfPlots;
    static std::vector<std::string> ListOfRegions;
    static Logger* LoggerInst;

    AbcdBase();
    virtual ~AbcdBase();

    typedef enum {
        A = 1, B = 2, C = 3, D = 4
    } RegionEnum;
    typedef enum {
        MET = 1, ETCONE20 = 2
    } DimensionEnum;

ClassDef(AbcdBase, 1)
};

Is a singleton the correct way of solving this issue? so that whenever DataSample or DoABCD need access to a member of AbcdBase they instance() function gets called which returns a pointer to a private instance of AbcdBase. I feel like this would clutter the code a LOT.

Thanks

  • 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-28T13:21:27+00:00Added an answer on May 28, 2026 at 1:21 pm

    Separately I have other classes (DataSample and DoABCD) that need access to those static members

    Merely declare those static member public, as you have done, and then reference them in any other code (including the code in DataSample or DoABCD:

    class DataSample {
      ...
      int GetFragle(void) {
        return AbcdBase::PlotHelperInst->m_fragle;
      }
      ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is
I have written a RNG class which holds different algorithms, however it does not
I have written a class in python that implements __str__(self) but when I use
I have written a class that will handle internal logging in my application. Now
I have written an apex class that will create a PDF quote and attach
In the library, right-click on a movieclip that you have written an ActionScript class
I have a class written in c# which is acting as a wrapper around
I have designed an ASP.NET page which create graphs. I have written a class
I have written one MapActivity class that is able to display a set of
I have written a simple class that works with a UIElement and an action

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.