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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:34:29+00:00 2026-06-10T06:34:29+00:00

a template class has all static members replicated for each instanciation of it. If

  • 0

a template class has all static members replicated for each instanciation of it. If I want a static member that exists only once for all instanciations, what should I do? Use a normal static field outside of the class template? Would work, but seems unelegant since there is no more association to the template class. Is there a way to somehow associate such unique static member with a template class?

  • 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-10T06:34:31+00:00Added an answer on June 10, 2026 at 6:34 am

    a template class has all static members replicated for each instanciation of it.

    Nope. It has different statics for each specialization, but different specializations are different classes. Make no mistake about it, vector<int> and vector<char> are totally separate. Think of it as writing IntVector and CharVector.

    EDIT: Don’t use inheritance for this. Introducing a base class just so you can share a static member is definitely the wrong way to go.

    If you want stuff shared between different classes, do it like you would usually do it. Wrap some statics in a third class and that’s it.

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

Sidebar

Related Questions

I want to use partial specialization for a template class so that all children
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
My base class, class Foo , is a template class which has the following
boost::shared_ptr has an unusual constructor template<class Y> shared_ptr(shared_ptr<Y> const & r, T * p);
I have a class which I cant change (SuperClass) that has an interface for
I have a 'static' template class alike the following: #include <cstddef> template <size_t elem_size>
I have a template class in a header that fails to compile, but when
OK, suppose I want to check whether the template parameter has a nested type/typedef
I have a template class, called OneCell , here the definition: template <class T>
I have a template class, called Cell , here the definition: template <class T>

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.