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

  • Home
  • SEARCH
  • 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 8328941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:36:15+00:00 2026-06-09T01:36:15+00:00

I have a ‘static’ template class alike the following: #include <cstddef> template <size_t elem_size>

  • 0

I have a ‘static’ template class alike the following:

#include <cstddef>

template <size_t elem_size>
struct StaticClass
{
    static void* priv;
};

So, the class contains only static members. As the static template implies, there should be one priv variable for each elem_size.

I also have the main template class which is already inherited from another class:

template <class T>
class MainBase
{
    // types, methods...
};

template <class T>
class MainDerived : public MainBase<T>
{
    // members, methods...
};

Now, I’d like MainDerived to be able to access StaticClass<sizeof(T)>; with the implication that different types T of the same size will access the same variable. What is the most optimal method of doing so? I’m mostly thinking about memory footprint.

AFAICS, having a non-static StaticClass<sizeof(T)> member in MainDerived increases the class size by 1 (for the size of ‘static’ class is 1).

So I’m thinking of either of three methods:

  1. Inheriting from the StaticClass (it’s a multiple inheritance then),
  2. Defining a static member of StaticClass type,
  3. Accessing StaticClass<sizeof(T)> in the methods directly.

All three methods will result in a similar source code (needing explicit specification of the class one way or another), and they all won’t affect sizeof(MainDerived<T>). I’m wondering if any of them has additional implications I should be aware of.

  • 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-09T01:36:17+00:00Added an answer on June 9, 2026 at 1:36 am

    I see a similarity with the standard library’s string class, which (in effect) has a typedef for a helper class with all static members, like

    typedef std::char_traits<T>   traits_type;
    

    and then uses traits_type::copy, traits_type::assign, etc, all through the rest of the code.

    You could do something similar with your StaticClass.

    typedef StaticClass<sizeof(T)>   sc;
    

    and then use sc::priv to access to correct pointer for each class.

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

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
Have a look at the following code to find X^y. /* Find exponent in
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>
Have the following scenario. I have a few form, which essentially have a few
Have the following code. The height is variable so the height of the floating
Have you managed to get Aptana Studio debugging to work? I tried following this,
have next code: class GameTexture { private: LPDIRECT3DTEXTURE9 texture; unsigned char *alphaLayer; UINT width,

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.