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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:23:07+00:00 2026-06-11T05:23:07+00:00

gcc 4.5.1, SuSE Linux i686 Suppose we have following code: template<typename realT> class B

  • 0

gcc 4.5.1, SuSE Linux i686

Suppose we have following code:

template<typename realT> class B
{
public:
    B() {std::cout << "B()" << std::endl;}
};

template<typename realT> class A
{
public:
    static B<realT> static_var;
};

template<typename realT> B<realT> A<realT>::static_var;
template<> B<float> A<float>::static_var;
template<> B<double> A<double>::static_var;

int main()
{
    A<float> test;
    return 0;
}

In this case we won’t have any output in the stdout. Compiler won’t generate code to initialize float and double specialization of class A.

But.. if we’ll change initializations like this:

template<> B<float> A<float>::static_var = B<float>();
template<> B<double> A<double>::static_var = B<double>();

the compiler will generate such code and we’ll have double “B()” in the output.

Can somebody help me with understanding of such behaviour?

  • 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-11T05:23:08+00:00Added an answer on June 11, 2026 at 5:23 am

    n3337 14.7.3/13

    An explicit specialization of a static data member of a template is a definition if the declaration includes an
    initializer; otherwise, it is a declaration.
    [ Note: The definition of a static data member of a template that
    requires default initialization must use a braced-init-list:

    template<> X Q<int>::x; // declaration
    template<> X Q<int>::x (); // error: declares a function
    template<> X Q<int>::x { };// definition
    

    — end note ]

    braced-init-list is C++11 feature, so in C++03 you can use only

    template<> X Q<int>::x = ...;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,
gcc 4.4.1 c89 I have the following code snippet: #include <stdlib.h> #include <stdio.h> char
gcc 4.4.2 c89 I have the following code. #if defined ( __linux__ ) log_msg(stderr,
gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,
gcc 4.1.2 c99 I have the following enum's in this file ccsmd.h : enum
gcc 4.4.2 c89 I have the following enum: enum drop_options_e { drop_ssm, drop_snm, drop_ssb
gcc 4.4.1 I am maintaining someone's code and I have come across something that
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: cannot find -lrtdk I can't find anything regarding this in the ld's manpage.
gcc 4.6.0 GNU Emacs 23.2.1 I have some c code and at some point
gcc 4.4.4 c89 I have always done the following when using structs to hide

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.