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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:24:25+00:00 2026-05-30T05:24:25+00:00

I tried to have one static const member variable to relate to another static

  • 0

I tried to have one static const member variable to relate to another static const variable in a class.
The motivation is that if I need to modify one value later (when coding), i don’t need to change all of those that are related to each other one by one.

For example:

class Box
{
    public:
        Box();
    private:
        static const double height = 10.0;
        static const double lid_height = 0.5 + height;
};

It won’t compile and the error was ”Box::height’ cannot appear in a constant-expression’. So I guess you must type in the value of a static const member. But is there a way to have one member relate to another member variable of the same class, given that they will all be static const??

  • 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-30T05:24:28+00:00Added an answer on May 30, 2026 at 5:24 am

    Set the value of your static const member variables outside of the class declaration, using the following syntax.

    // box.h
    #pragma once
    
    class box
    {
    public:
    static const float x;   
    };
    
    const float box::x = 1.0f;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one key but different values for that key. I tried HashTable but
I understand that one benefit of having static member functions is not having to
Does any one have tried to customize default section index displayed in UITableView. I
I have more than one OpenID as I have tried out numerous. As people
I would like to have more than one button. I tried to copy code
In my project I have a function named GetObject that is wrapped in one
I have a LINQ -> Class file named MoviesDB.dbml, I have added one table
I have tried to create a map like example below... var myMap= {one: 1,two:
We need to define a const static char pointer in each and every header
I have a class with many properties, one of them are byte[] property. I

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.