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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:31:29+00:00 2026-06-06T21:31:29+00:00

I would like to have a design suggestion from you. I have a set

  • 0

I would like to have a design suggestion from you.

I have a set of classes in C++, every class has a bunch of variables (double and int) which determines the behavior of the algorithms they implement.

Something like this:

class Foo
{
  private:
  double value1, value2, etc...;
  public: 
  void setOptions(double val1, double val2);
  /*
  and here other methods...
  */
};

class Bar
{
  private:
  double value1, value2, etc...;
  public: 
  void setOptions(double val1, double val2);
  /*
  and here other methods...
  */
};

I would like to group all these option variables in a single class, so that is possible to dynamically change the variables of the options in the instances of the classes, but I would also like to give the value variables a default value as initialization.

I would like that the options variables are different and set with a default value at compile time for every class.

I adopted the following approach:

// Options.h
class Options
{
    public:
    Options();

    static struct FooOptions
    {
      static double option1;
      static double option2;
    } fooOptions;

    static struct BarOptions
    {
      static double option1;
      static double option2;
        // etcetera
    } barOptions;  
};

and then in the Foo and Bar classes I use the value Options::FooOptions::option1 and so on.

The problem here is that I can’t initialize those value statically.
I’m used to initialize static member outside in the .cpp file, but in my .cpp

// Options.cpp
Options::FooOptions::option1 = 1.0;

I get the following compiler
error: error: expected constructor, destructor, or type conversion before ‘=’ token

On other hand if I initialize them inside the constructor:

// Options.cpp
Options::Options()
{
    FooOptions::option1=1.0;
}

I get undefined reference error when I try to access it from my main.

I think the problem here is that I have two nested static structures. What can be here an optimal solution for this kind of design?

How would you implement a class that acts only as container of double and int values to use inside classes as parameters of algorithms?

  • 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-06T21:31:32+00:00Added an answer on June 6, 2026 at 9:31 pm
    // Options.cpp
    Options::FooOptions::option1 = 1.0;
    

    Add the missing “double” 🙂

    double Options::FooOptions::option1 = 1.0;
    

    should do it.

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

Sidebar

Related Questions

I have a XAML file that I exported from Expression Design. I would like
I have to design a GUI using Qt. I would like to draw multiple
I have this design which I cannot seem to get right, I would like
I have an OS design project with some subprojects, I would like to try
I have an UserControl and would like to hide the resizing handles in design-time,
So in my project i would like have a nice treeview that has images.
I would like to have a field which is updated on every change(insertion, modification),
I would like to have an AppWidget that designed like this one . Image:
I would like to have a more colorful Python prompt in the terminal, just
I would like to have the cursor in the JavaDoc area when creating interfaces,

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.