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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:38:39+00:00 2026-06-02T07:38:39+00:00

I have a class consisting solely of static attributes acting as a sort of

  • 0

I have a class consisting solely of static attributes acting as a sort of poor man’s singleton. The purpose of which is to collect statistics from various points in the application. For our unit tests I created a shadow copy that can be used to get the difference between the one in production code.

Example:

struct Production {
    static ComplexClass value1;
    static ComplexClass value2;
};

struct ProductionShadow {
    static ComplexClass::ValueType value1;
    static ComplexClass::ValueType value2;
};

Since all members are static the shadow class cannot inherit from the production class and the attributes in the production class are complex objects with side effects and I only want the shadow to hold simple values for comparison.

In order to make the shadow class somewhat easier to maintain I wanted to add a static assert to check that whenever someone adds an attribute to the production class the shadow class is also updated.

Had the attributes not been static this could have easily been accomplished by doing the following:

enum { NumberOfProductionAttributes = sizeof(Production) / sizeof(ComplexClass),
       NumberOfShadowAttributes = sizeof(ProductionShadow) / sizeof(ComplexClass::ValueType) };
STATIC_ASSERT(NumberOfProductionAttributes == NumberOfShadowAttributes);

Apart from making the classes non-static, which I’d rather not do as I would have to turn the production class into a proper singleton, is there any way I can accomplish this check with the current implementation?

In runtime I have a method that verifies all the values in the shadow with the production class. Since the method has to be updated as well when a new attribute is added I would like to be able to count the number of attributes that have been verified and assert if the amount is different from the total number of attributes.

Example

bool ProductionShadow::verify() {
    std::size_t numberOfVerified = 0;
    #define VERIFY(x) do { \
        ++numberOfVerified; \
        // Verification code goes here \
    } while (0)
    VERIFY(value1);
    VERIFY(value2);
    ASSERT(numberOfVerified == NumberOfShadowAttributes);
    // Return result
}

If there is a GCC extension I can use that might be an acceptable solution even though I would prefer something portable.

  • 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-02T07:38:40+00:00Added an answer on June 2, 2026 at 7:38 am

    Just in case, here is the solution I suggested in the comments to the question. The idea is to create two classes that contain the data members in question in the form of non-static members:

    struct ProductionStaticMembers
    {
      ComplexClass value1;
      ComplexClass value2;
    };
    
    struct ProductionShadowStaticMembers
    {
      ComplexClass::ValueType value1;
      ComplexClass::ValueType value2;
    };
    

    And then redefine the original classes to contain the classes defined above as static members. They would continue to function as before, and size checks could be performed against the types defined above.

    struct Production {
      static ProductionStaticMembers static_members;
    };
    
    struct ProductionShadow {
      static ProductionShadowStaticMembers static_members;
    };
    

    Admittedly, this means a change in how the static members are accessed (because they are now members of another member); therefore many changes to existing code might be required.

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

Sidebar

Related Questions

I have a class library containing several structures each consisting of several value and
I have class A, which exposes an event. an object of class B subscribed
I have WPF treeView which has ControlTemplate which show every node of treeView consisting
I have a bare bones ORM implementation, consisting of data mappers which load and
Here's a very simple AS3 project consisting of one class which draws a rectangle.
I have a database table consisting of countries. In my DAO which extends HibernateDAOSupport
I often have to sort a dictionary (consisting of keys & values) by value.
I have a class A consisting of a bunch of internal data structures (e.g.
In most of the web application, i have seen one base class consisting common
I have a PHPUnit test case class (consisting of some test functions). I would

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.