When I Am Implementing Function Prototypes

Hi,

Very new to c++.

I am using VS2008 with pre-compiled headers. Let's say I have this:

[player.h]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _PLAYER_
#define _PLAYER_

class player
{

//fields
public: 
	char * name;

//constructors
public:
	player();

public:
	player(char * name);

//methods
public:
	bool validate();

};

#endif 


[player.cpp]

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "player.h"

player::player(){}

player::player(char * name)
{
	this->name = name;
}

bool player::validate()
{
	return true;
}


This won't compile because VS2008 whines about the pre-compiled header "stdafx.h". If I include this header into player.cpp then it will compile. The thing I don't understand is why player.cpp needs to include stdafx.h. Do I have to include the pre-compiled header in every file I create?

Also, in terms of general c++ structure, have I done everything correctly?

Hope that makes sense.

Thanks
Why don't you switch off precompiled headers. For non-MFC projects, they can be more trouble than they're worth.
I realize I can do this, but I am trying to understand the theory behind it. In my mind it doesn't make sense, what association does player.cpp have with the pre-compiled header?
The Wizard set's up precompiled headers as follows:
- The header that's precompiled is stdafx.h and the file that it's pre-compiled with is stdafx.cpp.
- Each compiled unit must include stdafx.h first so that the compiler can read the precompiled information.
- If you change stdafx.h or a header file that it depends on, you must recompile stdafx.cpp to regenerate the corrected precompiled information and necessarily all the other compiled units too.

Borland implemented a much easier to use precompiled header scheme--but such advanced technology is lost in the mysts of history.
Thanks
Topic archived. No new replies allowed.