#include <iostream>
#include <string>
usingnamespace std;
int main(void)
{
class Bow
{
public:
string color;
bool drawn;
int numOfArrows;
Bow(string aColor);
~Bow();
void draw();
int fire();
};
void Bow::draw() //Error:Draw() may not be redeclared outside of it's class.
{
drawn=true;
cout << "The " << color << " bow has been drawn.\n";
}
int Bow::fire()
{
if(!drawn)
{
cout << color << " has not been drawn " << "and therefore could not fire.\n";
return 0;
}
int score;
score=rand()%(10-0+1)+0;
if(score==0)
cout << color << " missed the target!!!\n";
else
cout << color << " scored " << score << " points\n";
return score;
}
}
Error 5 error C2601: 'main::Bow::draw' : local function definitions are illegal d:\documents\code\c++\scrap\scrap\main.cpp 20
Error 6 error C2601: 'main::Bow::fire' : local function definitions are illegal d:\documents\code\c++\scrap\scrap\main.cpp 26
I think I can still use the keyword inline in front of the function definition outside of the class and it will make it inline. Whether or not the compiler chooses to copy the function everywhere it is called, varies from compiler to compiler.