I wrote some basic code I learned that can be used to define a type that gets an enumerated value as its constructor argument and has a member function AsString()
that returns the value as a string.
The code doesn't compile unless I include <iostream>
. It displays a warning in main
saying that the type color
has not been declared. Why is it required to include an input/output header file in my code while no input/output functions or operators are used in it?
enum ColorEnum {blue, red};
class color
{
protected:
ColorEnum value;
public:
color(ColorEnum initvalue)
{
value = initvalue;
}
std::string AsString()
{
switch (value)
{
case blue:
return "blue";
case red:
return "red";
default:
return "N/A";
}
}
};
int main()
{
color mycolor = blue;
return 0;
}