The initialization of the static member counter
must not be in the header file.
Change the line in the header file to
static int counter;
And add the following line to your employee.cpp:
int Employee::counter = 0;
Reason is that putting such an initialization in the header file would duplicate the initialization code in every place where the header is included.
Related Posts:
- The static keyword and its various uses in C++
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- c++ compile error: ISO C++ forbids comparison between pointer and integer
- error: redefinition of class
- C++ Error: No match for ‘operator=’
- Identifier not found error on function call
- What is an ‘undeclared identifier’ error and how do I fix it?
- Identifier not found error on function call
- What is an ‘undeclared identifier’ error and how do I fix it?
- C ++ error: a expected initializer before [function name]
- invalid new-expression of abstract class type
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- error: redefinition of class
- C++ error: “Array must be initialized with a brace enclosed initializer”
- What is the difference between a static and const variable?
- error: expected primary-expression before ‘)’ token (C)
- Is “argv[0] = name-of-executable” an accepted standard or just a common convention?
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- Static array vs. dynamic array in C++
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- Is std::stoi actually safe to use?
- Is std::stoi actually safe to use?
- Resolve build errors due to circular dependency amongst classes
- C++ error: definition of implicitly-declared
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- extra qualification error in C++
- Cannot open output file, permission denied
- Is there a standard C++ grammar?
- Call to non-static member function without an object argument compiler error
- Error “Unterminated conditional directive” in cross-referencing headers
- Don’t understand static boolean behavior
- multiple definitions error in c++ and solution to solve this issue
- Stray ‘\342’ in C++ program
- System not declared in scope?
- Error in assignment of member in read-only object
- Call of overloaded function is ambiguous
- How to determine the version of the C++ standard used by the compiler?
- How to determine the version of the C++ standard used by the compiler?
- Error: expression cannot be used as a function?
- Does static constexpr variable inside a function make sense?
- Why virtual & static keywords aren’t allowed outside class declaration?
- Unexpected end of file error
- virtual memory exhausted: Cannot allocate memory
- Compiler error C4430: missing type specifier – int assumed [duplicate]
- Member function with static linkage
- Floating point exception( core dump
- Passing Arrays to Function in C++
- Return array in a function
- How does the modulus operator work?
- Single class has a Class Redefinition Error
- Debug assertion failed. C++ vector subscript out of range
- What causes a SIGABRT fault?
- Graphics Library for C++
- ‘cout’ was not declared in this scope
- What is the difference between const int*, const int * const, and int const *?
- Socket Programming in C++
- warning: ISO C++ forbids variable length array
- cin >> “no operator matches these operands”
- C++ Structure Initialization
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- Enum to String C++
- Random float number generation
- “Error: expression must have a pointer type” when using the “this” keyword
- C++ #include guards
- glm rotate usage in Opengl
- error: member access into incomplete type : forward declaration of
- Debug assertion failed
- “Implicit instantiation of undefined template” when forward declaring template class
- “…redeclared as different kind of symbol”?
- Error “system” is ambiguous?
- android,
android-layout,
android-linearlayout,
gradient, - Reading multiple lines from a file using getline()
- invalid use of non-static data member
- C: using strtol endptr is never NULL, cannot check if value is integer only?
- use of class template requires template argument list
- Why would this give a Use of uninitialised value of size 8
- C++ Error: Type Name is Not Allowed
- How to memset char array with null terminating character?
- Converting from Radians to Degrees
- The system cannot find the file specified. in Visual Studio
- Python for C++ Developers
- Remove last character from C++ string
- plotting package for c++
- Passing as const and by reference – Worth it?
- Understanding Recursion to generate permutations
- In C++ what does template<> mean?
- Two decimal places using printf( )
- error C2244 unable to match function definition to an existing declaration
- Initializing pointers in C++
- Static vs dynamic type checking in C++
- “No rule to make target ‘install'”… But Makefile exists
- What does “warning: not all control paths return a value” mean? (C++)
- Array of Linked Lists C++
- Is it still safe to delete nullptr in c++0x?
- Declaration is incompatible with type
- One or more multiply defined symbols found
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization