header in multiple .cpp files?
ok so here is my problem if i include gotoxy.h file to 1 .cpp fille it works fine but as soon as i try adding it to 2 files it gives me this error
Code:
1>------ Build started: Project: SimpleRPG, Configuration: Debug Win32 ------
1>Build started 25/07/2011 11:41:37 AM.
1>InitializeBuildStatus:
1> Touching "Debug\SimpleRPG.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>test.obj : error LNK2005: "void __cdecl Gotoxy_color(short,short,short)" (?Gotoxy_color@@YAXFFF@Z) already defined in GFX.obj
1>test.obj : error LNK2005: "void __cdecl Color(short)" (?Color@@YAXF@Z) already defined in GFX.obj
1>test.obj : error LNK2005: "void * hConsole" (?hConsole@@3PAXA) already defined in GFX.obj
1>Debug\SimpleRPG.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.76
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
gotoxy.h
Code:
#ifndef GOTOXY
#define GOTOXY
#include <Windows.h>
HANDLE hConsole;
void Gotoxy_color ( short x ,short y, short color)
{
COORD Goto = {x, y};
SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), Goto );
SetConsoleTextAttribute ( GetStdHandle ( STD_OUTPUT_HANDLE ), color );
}
void Color ( short color )
{
SetConsoleTextAttribute ( GetStdHandle ( STD_OUTPUT_HANDLE ), color );
}
#endif GOTOXY
Could some one help me? what did i miss? i am a newbie i haven't touched c++ in a while, schools over and i have TONS of free time but this kinda annoys me i am sure you can use one header file in multiple .cpp files right? so whats wrong :S