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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:15:54+00:00 2026-05-14T05:15:54+00:00

I have a class class foo { public: foo(); foo( int ); private: static

  • 0

I have a class

class foo {
public:
   foo();
   foo( int );
private:
   static const string s;
};

Where is the best place to initialize the string s in the source file?

  • 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-14T05:15:55+00:00Added an answer on May 14, 2026 at 5:15 am

    Anywhere in one compilation unit (usually a .cpp file) would do:

    foo.h

    class foo {
        static const string s; // Can never be initialized here.
        static const char* cs; // Same with C strings.
    
        static const int i = 3; // Integral types can be initialized here (*)...
        static const int j; //     ... OR in cpp.
    };
    

    foo.cpp

    #include "foo.h"
    const string foo::s = "foo string";
    const char* foo::cs = "foo C string";
    // No definition for i. (*)
    const int foo::j = 4;
    

    (*) According to the standards you must define i outside of the class definition (like j is) if it is used in code other than just integral constant expressions. See David’s comment below for details.

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

Sidebar

Ask A Question

Stats

  • Questions 506k
  • Answers 506k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the site documentation: $image = new gd_gradient_fill($width,$height,$direction,$startcolor,$endcolor,$step) string $direction… May 16, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer This is correct. bundle install won't install Rails as a… May 16, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer Doesn't the database need it to be in HH:MM:SS (H:i:s)… May 16, 2026 at 3:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a class namespace LogToolsTest { public class Foo { private static readonly
Let's say I have this program: class Foo { public: unsigned int bar ()
Lets say I have business class: public class Foo { public int Prop1 {get;set;}
Assume we have legacy classes, that can't be modified: class Foo { public void
I have a random question about const correctness. Lets say i have a class
I have a linked list structure: struct SomeLinkedList { const char* bar; int lots_of_interesting_stuff_in_here;
I have a class Foo with a field UpdateMe of type Confirmation as described
When I have a class containing static stuff, how can I free the memory
I have a dummy class where I am testing arrays. I've noticed that when
Given the following template: template <typename T> class wrapper : public T {}; What

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.