Hey guys I am working on a homework assignment for my programming languages class, and I am stuck because of a compile error. My assignment is implementing a reverse polish calculator. My design goal was to create an interface called commands that will have a pure virtual function called execute(). I subclass commands with classes such as Add, Subtract and so fourth. When the user inputs '+', I will use that as the key for the Add command in the map, so I can easily grab the commands based on the user input. However, in all of my subclasses, the compiler gives the error "undefined reference to stack". I forgot to mention that I have a Stack as a protected member in the Command class. Here is the line where I get the error: https://github.com/haglerchristopher/RPN-Calculator/blob/master/src/Print.cpp#L22
and this is the command class: https://github.com/haglerchristopher/RPN-Calculator/blob/master/src/Command.h If you are able to help please don't give me any answers to anything. I would just like a nudge in the right direction to get past the compile error because I do not want to cheat and possible receive a zero grade. Thanks for all of the help.
> Why is it that you have to define it in the .cpp file
C++ makes a distinction between a declaration and a definition.
The static data member is declared inside the class definition. It has external linkage, and must be defined (at namespace scope), once (and only once) in the entire program.
> when should you ever declare class variables in the header?
Member variables are always declared within the class definition.
Static member variables (not associated with specific objects) are defined at namespace scope.
Static members are subject to member access control (private, protected, public).