Just wondering if the language will know that I intend to return ONLY ONE VALUE. Here is my function (I have a sentry variable, but was trying to avoid adding algorithmic complexity):
bool assemblytoopcode::checkduplicates()
{
for (int j = 0; j < (int)labels.size(); j++)
{
for (int k = j; k < (int)labels.size(); k++)
{
if (k = j)
{
//Do nothing; the compiler won't let me define k > j...
} //end if
elseif ((labels[j] == labels[k]) && (k > j)) //If the label is already in the vector...
{
cout << "ERROR: Label "<<labels[j]<<" on line "<<j<<" already exists."<<endl; //Report that incident to the user!!
goto returnerror; //Get me out of here!!
} //end else if
} //end inner for
} //end outer for
returnfalse;
returnerror: returntrue;
} //end checkduplicates
return immediately exits the function, so the compiler does not have to know anything. It'll do the right thing.
What's the goto supposed to accomplish? Replace it by return true; directly.
This is an assignment, by the way: if (k = j)
And you can negate a condition, no need for strange else constructs:
1 2 3 4
if (!(labels[j] == labels[k] && k > j)) //If the label is already in the vector...
{
[...]
}
or if (labels[j] != labels[k] || k <= j) //If the label is already in the vector...