Linked Questions

0 votes
2 answers
105 views

I have a class whose static const members have the same type as the class. I am getting an error that class isn't yet complete. #include<iostream> class Color { public: Color(unsigned char ...
Praveen Kumar's user avatar
147 votes
5 answers
197k views

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?
Thomas's user avatar
  • 2,979
7 votes
3 answers
18k views

Why I cannot initialize a static const char* in the header file? In my code I have in my Class header: static const char* xml_ID_TAG; and in the cpp: const char* Class::xml_ID_TAG = "id"; The ...
ABCplus's user avatar
  • 4,041
3 votes
3 answers
5k views

I keep getting this error: warning: non-static const member ‘const char sict::Weather::_date [7]’ in class without a constructor [-Wuninitialized] And i don't understand it. main.cpp #include &...
Sophia McDonald's user avatar
5 votes
1 answer
1k views

As far as I know, you can only initialize static const members in the same line of their declaration if they are integral types . However, I was still able to initialize and use some static const ...
guivenca's user avatar
  • 179
1 vote
2 answers
3k views

I want to run this code: struct A { static const string d[] = {"1", "2"}; }; And get an error: error: in-class initialization of static data member ‘const string A::d []’ ...
dasfex's user avatar
  • 1,380
2 votes
2 answers
288 views

Consider the following piece of code. class aClass { public: static const int HALLO = -3; }; int main() { std::vector<double > a; std::vector<int> b; std::vector<int> c; ...
Ricardo's user avatar
  • 265
2 votes
1 answer
2k views

The questions is where to initialize static const member in c++17 or newer? Please consider the following two solutions for initializing a static const member in c++: Solution 1 (for c++14 or older): ...
BlueTune's user avatar
  • 1,063
1 vote
2 answers
603 views

Okay, after searching myself half to death and not finding any answer that actually seemed to work I gotta ask: Say I've got a class (contrived example, but hopefully good enough for now) template &...
Johann Studanski's user avatar
2 votes
0 answers
268 views

I am implementing a new header-only Library in VS2019, targeting C++11. As discussed (How to initialize a static const member in C++?) you cannot initialize a non-int static class member in-line. ...
Mr. Boy's user avatar
  • 64.5k
1 vote
1 answer
135 views

// gamewindow.hpp #include <SFML/Graphics.hpp> #include <string> #include <cstdint> class GameWindow : public sf::RenderWindow { public: GameWindow(const uint32_t&, const ...
Sean Pianka's user avatar
  • 2,355
0 votes
1 answer
118 views

I'm using std::make_unique (std::make_shared) to instantiate a class that takes a parameter. This parameter shall be initialized by a static constant. If this static constant is initialized by a ...
AKr143's user avatar
  • 3
2 votes
0 answers
67 views

This problem of mine was reproduced on cpp.sh with C++14 activated (I don't know if that is relevant...) I have this program: // Example program 1 #include <iostream> #include <vector> ...
Martin G's user avatar
  • 18.4k