When attempting to compile my code, I get a total of 6 errors. I have been working on 2 of them, and cannot figure them out.
error: id.cpp:26: error: âage_â was not declared in this scope
function:
void SetAge (int a)
{
age_ = a;
}
The prototype for this function is in file id.h, under class ID and age_ is a private variable in class ID. The class also has a private variable name_, but I'm not receiving any errors in functions which use it.
You need to explicitly tell the compiler that SetAge is a member method of class ID like that:
1 2 3 4
void ID::SetAge (int a)
{
age_ = a;
}
The second problem is that you want to pass a parameter of type ID to the function operator<<, so just as you do with any other parameter, you need to provide a name for it and use this name in the function body:
1 2 3 4 5
std::ostream& operator << (std::ostream & os, ID param)
{
os << param.Cstr ();
return os;
}
Thanks for the help. After a few hours on it, since I knew I wasn't supposed to be adding any more functions to the program, I realized I didn't even need the Cstr(). Here's what I've got so far: