Hi, I am getting an error in my class that I do not understand.
The error message says
Bow class.cpp In member function `void Bow::draw()':
class.cpp `color' undeclared (first use this function)
I am just being dumb as I really can't see the problem. I have delcared color as a private member, so why the error? Should I get more coffee? ( chuckle!) thanks in advance
Code:
class Bow
{
private:
string m_color;
bool drawn;
int numOfArrows;
public:
Bow( string Color);
~Bow();
void draw();
int fire();
};
// constructor inplementation for Bow class
Bow::Bow ( string Color )
{
srand(time(0));
m_color = Color;
numOfArrows = 10;
drawn = false;
}
// deconstructor for Bow class
Bow::~Bow()
{
}
// draw method implementation - draws the bow
void Bow::draw()
{
drawn = true;
cout << "The " << color << " has been drawn" << endl;
}
// fire method implementation - fires the bow if drawn
int Bow::fire()
{
if (!drawn ) // if not drawn
{
cout << color << " has not be drawn and cannot fire" << endl;
return 0;
}
int score;
score = rand() % ( 10 - 0 + 1 ) + 0;
if ( score == 0 )
cout << color << " missed the target!" << endl;
else
cout << color << " scored " << score << " points!!" << endl;
return score;
}
void bowTest ( void ); // function prototype
// driver -- main
int main ( void )
{
bowTest();
return 0;
}
// text challis - checks if class works
void bowTest ( void )
{
Bow yellow ("yellow");
yellow.fire();
yellow.draw();
yellow.fire();
}