Timeline for error: ISO C++ forbids in-class initialization of non-const static member
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 10 at 9:16 | comment | added | Andreas Otto | this is right if the class is defined in a header(h) file but if the class is defined in the code(cc) file this is just an extra unnecessary step. | |
Oct 16, 2017 at 8:43 | comment | added | PMF | @JesusChrist: Not sure. Either it wouldn't matter if the const member got a new memory location every time (in fact existing multiple times) or not at all (because it gets eliminated by the compiler) | |
Sep 5, 2017 at 20:14 | comment | added | BozanicJosip | if that's sole reason why it's prevented, why const members are allowed? Don't they get initialized in every place where the header is included aswell? | |
Dec 1, 2013 at 17:03 | vote | accept | mishelashala | ||
Dec 1, 2013 at 14:59 | comment | added | mishelashala | Because i did another one. But it does not matter. Thank for the info | |
Dec 1, 2013 at 13:18 | comment | added | PMF | @user3053929: Where did you put it? It needs to be outside any function but where the class Employee is known. BTW: Why is your cpp file called employee2.cpp? And including employee2.h? | |
Dec 1, 2013 at 10:18 | history | edited | PMF | CC BY-SA 3.0 |
Fixed small error
|
Dec 1, 2013 at 8:18 | comment | added | mishelashala | I did it, but it returns: In function ‘int main()’: error: ‘int Employee::counter’ is private error: within this context | |
Dec 1, 2013 at 8:01 | history | answered | PMF | CC BY-SA 3.0 |