Function Redeclaration?

I'm pulling my hair out over this one, it's got to be a bracket out of place!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
using namespace 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
Last edited on
AHHH I Figured it out!!!

I have the class defined inside of main when it should be outside, I am such an idiot!
Thanks all anyway!
You *might* be doable if you removed the extraneous Bow:: from the function names. The class is already in scope, you don't need to re-scope it.
^ Nope. ¿what are you talking about?
You could define the methods inside the class.
I was talking about how doing Bow:: disables inlining...
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.
Topic archived. No new replies allowed.