I'm starting my assignment for c++ after working on java, and have a little problem that I can't seem to get rid of. When ever i try to compile my program, i get a ton of [Linker Error] undefined reference to *insert class::variable here* errors. Now I'm sure it's probably something that I've accidentally carried over from java, but even after a few hours on the net looking for answers, I can't seem to find one.
I suspect it is because you have declared all your member variables as statics. The first two are OK as they are. You either need to take the static keyword out of the last three like this
They don't appear to need to be static so I would recommend the first option. One problem that I have spotted are you for loops. By putting the double plus before the i you are incrementing i before each loop is executed so i will never be zero. Put the double plus after the i to increment after each loop is executed. For example, isGoodSwitchCount() needs to look like this
1 2 3 4 5
bool validate::isGoodSwitchCount()
{
for( int i = 0; i < validate::COMMAND_COUNT; i++)
{
. . .
I have a couple of minor comments on your code. Although the line
using std::string;
in validation.h is perfectly valid, it is more usual to write
usingnamespace std;
unless you need to exclude the rest of the std namespace. Another point is that, again it is perfectly valid, but you do not need to put the validate:: prefix to reference symbols within the same class. The only reason for doing this would be if you have symbol name conflicts with another class you are using in which case the compiler will usually complain.
Turns out it was the static *smacks head into a wall* thanks!
To the best of my knowledge (aka, java), the incriment was done after all the code in the loop was finished, as such not altering the loop sequence, I may be wrong though, and its always better to be safe than sorry!
With the namespace std, my instructors have told us that somewhere in this program functions will be clashing. Besides that, as I'm just starting, I like to see where what I'm using is coming from. Though I use namespace for debugging purposes (to make sure i havent forgotten something).
Thanks for that! I'll make sure to check that out (as Im already getting sick of typing class names hehe).
Thanks, I tend to get lost in my own code if I dont keep it atleast semi-neat.