Linked Questions

0 votes
2 answers
1k views

#include "stdafx.h" #include <iostream> class X { public: static int n; }; int X::n; // out-of-class initialization int _tmain(int argc, _TCHAR* argv[]) { X x; std::cout <&...
madu's user avatar
  • 5,470
2 votes
1 answer
2k views

I know this question has already been asked, but googling around I didn't find a real answer to it. What I mean is: static member functions (and also non-static ones, for that matter) can be defined ...
UndefinedBehavior's user avatar
1 vote
2 answers
198 views

Consider the following code: #include "stdafx.h" #include <iostream> class Eelement { public: static int m_iVal; }; int Eelement::m_iVal = 33; int main() { //... return 0; } ...
Landstalker's user avatar
  • 1,368
1 vote
0 answers
179 views

I'm using C++17 and stumbled on a linker error with this kind of code #include <memory> struct SomeType { static const int MIN = 0; static const int MAX = 0; }; struct Range { ...
Allan Ojala's user avatar
1 vote
0 answers
80 views

Here is some code: class aclass { int x = 1; static float peanut; //definition not allowed here or in any other class }; float aclass::peanut = 5.2; //definition seems to only be allowed at ...
user avatar
1 vote
1 answer
77 views

Attempted to build a doubly linked list and printing it out. However, I received a linker command failed after adding "static Node* lastAdded". Not sure what the reason is. Also, for the head node, I ...
CoffeeSyntax's user avatar
0 votes
0 answers
54 views

I was coding a class template to implement a Singleton when an issue occured. While having a static pointer in a .h file, it wouldnt compile because of a linker issue (lnk 2001 and lnk 1120 on vs 15)....
Arkhain's user avatar
  • 31
0 votes
0 answers
45 views

This code works fine as an implementation of Singleton pattern. I want to understand Singleton *Singleton::obj = 0;. What is that doing and why is that important? Please explain. #include <...
Aquarius_Girl's user avatar
0 votes
0 answers
38 views

using namespace std; class singleton_l //lazy { private: singleton_l(){cout << "lazy singleton created" << endl;} ~singleton_l(){} static ...
Joe's user avatar
  • 57
1 vote
0 answers
33 views

I'm using Xcode 9.0 for a school assignment, a simple command line program. Getting these odd errors related to static class vars in my one class. I have read several similar questions and have tried ...
K. Olivier's user avatar
105 votes
3 answers
123k views

Before C++11, we could only perform in-class initialization on static const members of integral or enumeration type. Stroustrup discusses this in his C++ FAQ, giving the following example: class Y { ...
Joseph Mansfield's user avatar
34 votes
6 answers
47k views

I am trying to define a public static variable like this : public : static int j=0; //or any other value too I am getting a compilation error on this very line : ISO C++ forbids in-...
dev's user avatar
  • 11.4k
26 votes
4 answers
6k views

I know that non-constant static variables need to be initialized outside the class definition but, is there a reason for this? class A { static int x = 0 // compile error; static int y; }; ...
Blasco's user avatar
  • 1,754
29 votes
5 answers
5k views

In the class: class foo { public: static int bar; //declaration of static data member }; int foo::bar = 0; //definition of data member We have to explicitly define the static variable, otherwise ...
shauryachats's user avatar
  • 10.5k
28 votes
3 answers
2k views

Scott Meyers writes in Effective Modern C++ (Item 30, at page 210) that there's no need to define integral static const data members in classes; declarations alone suffice, then the sample code is ...
Enlico's user avatar
  • 30.3k

15 30 50 per page