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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:00:50+00:00 2026-06-07T04:00:50+00:00

I am sorry for my newbie question, but I do not know much about

  • 0

I am sorry for my newbie question, but I do not know much about C++. Can anybody answer why I get the error “error: a call to a constructor cannot appear in a constant-expression” when compiling following code;

class EliminationWeight
{
 public:
    typedef double Type;
    static const Type MAX_VALUE = __DBL_MAX__;
    static const Type MIN_VALUE = -__DBL_MAX__;
};

I use Ubuntu 12.04 and gcc that comes with it. It is not my code and I know that this code probably it works OK 100% (perhaps in older version of gcc or other compiler). Is there a quick way to fix it?

Thanks in advance for any answers, this is actually my first time asking something at SO.

  • 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-07T04:00:52+00:00Added an answer on June 7, 2026 at 4:00 am

    Call to a constructor cannot appear in a constant-expression is a GCC error message which doesn’t really make sense to me here. Clang, for instance, accepts your code with some warnings:

    test.cpp:31:23: warning: in-class initializer for static data member of type
          'const Type' (aka 'const double') is a GNU extension [-Wgnu]
        static const Type MAX_VALUE = __DBL_MAX__;
                          ^           ~~~~~~~~~~~
    

    Anyway, initializing double in a class body is non-standard. You should do initialization separately:

    class EliminationWeight
    {
     public:
        typedef double Type;
        static const Type MAX_VALUE;
        static const Type MIN_VALUE;
    };
    

    and then in exactly one source file (not a header file):

    const EliminationWeight::Type EliminationWeight::MAX_VALUE = __DBL_MAX__;
    const EliminationWeight::Type EliminationWeight::MIN_VALUE = -__DBL_MAX__;
    

    In general, you can only initialize static member variables having integral types in class body, although this has been extended in C++ 0x11. See also Initializing const member within class declaration in C++

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

Sidebar

Related Questions

Sorry for the complete newbie question but i'm not having much luck. I've created
Sorry for this newbie question, but I can't find on google what I need
Sorry for the newbie question but still very new to Ruby and Mongo. Not
Sorry for the newbie question, but I can't seem to figure this out. I
Sorry for this newbie question but I cannot figure how I can do this..
I'm sorry for this newbie question, but I need a quick answer to tell
fans Sorry for this newbie question, but I can't find on google what I
fans Sorry for this newbie question, but I can't find on google what I
Sorry for newbie question but is there a way to import someone else commit
sorry for a newbie question.. but Service by it's defenision meaning the same as

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.