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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:02:32+00:00 2026-05-13T19:02:32+00:00

I have problem with the syntax needed to initialize a static member in a

  • 0

I have problem with the syntax needed to initialize a static member in a class template. Here is the code (I tried to reduce it as much as I could):

template <typename T>
struct A
{
  template <typename T1>
  struct B
  {
    static T1 b;
  };

  B<T> b;
  typedef B<T> BT;
  T val() { return b.b; }
};

template <typename T>
T A<T>::BT::b;

struct D
{
  D() : d(0) {}
  int d;
};

int main()
{
  A<D> a;
  return a.val().d;
}

With g++, the error I get is:

error: too few template-parameter-lists

Any ideas how to initialize b?

Note that I would like to keep the typedef, as in my real code, B is way more complex than that.

  • 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-13T19:02:33+00:00Added an answer on May 13, 2026 at 7:02 pm

    Change the definition of b to the following:

    template <typename T> template<typename T1>
    T1 A<T>::B<T1>::b;
    

    Notice that the typedef and B<T1> don’t necessarily specify the same type: While the typedef relies on T being passed to B, B<T1> relies on the template parameter T1 being passed. So you cannot use the typedef here to specify a definition for b in B<T1>.

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

Sidebar

Related Questions

Ok, so maybe my search syntax is wrong here, this could have very well
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a weird problem with my mysql query syntax. I have made a
I have been trying to find ways to solve the problem. Firebug said syntax
I have problem with Razor syntax and jQuery, I'm trying to append some items
I have a syntax problem using Actionscript. Can I create new objects from inside
Sometime we have problem with the file PATH syntax For example Wrong PATH as
I have problem with this piece of code: var el = $('div#editor'); el.find('*[contentEditable]').removeAttr('contentEditable'); It
I have problem implementing the operator!= in a set class deriving from an abstact
I have a problem in that the syntax for datediff in mysql is different

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.