- Joined
- Jul 18, 2006
- Messages
- 1
- Reaction score
- 0
I have one small problem with my project. Let's say thah I am creating new console win32 aplication, and I am using precompiled headers ["stdafx.h"]. Now I create an additional header file with all the data tables I'll be using in my classes called for example "data.h", where I put :
and this file I am including in stdafx.h [#include "data.h" etc
]
Then I create first class called "foo" [using wizard]. VS created two files : "foo.h" and "foo.cpp". Now I modify a bit these files and finaly :
main.cpp
stdafx.h
stdafx.cpp
foo.h
foo.cpp
and that is enough for Visual to throw linker error LNK2005 which says that :
any idea how to solve it ? of course this is just an example ... real data.h contains a lot of "const int N_sht", "char _some_name_tables[x][y]", "enum enum_types {bla1,bla2}" etc ...
Why not to implement it in foo.h file ? because in my project are few classes that uses this data so i thougt it should be stored in some external file and then just include it whenewer I need it ... I know that this idea could be crappy
then please tell me how can I do it more efficiently
IvaN
Code:
char _race_names[3][20]={"Human","Ghoul","Mutant"};
Then I create first class called "foo" [using wizard]. VS created two files : "foo.h" and "foo.cpp". Now I modify a bit these files and finaly :
main.cpp
Code:
#include "stdafx.h"
#include "foo.h"
int main(int argc, char *argv[]) {
foo tmp;
tmp.show();
return 0;
}
stdafx.h
Code:
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include "data.h"
#include <tchar.h>
Code:
#include "stdafx.h"
Code:
#pragma once
using namespace std;
class foo {
public :
foo(void);
show(void);
~foo(void);
}
Code:
#include "stdafx.h"
#include "foo.h"
foo::foo(void){
}
foo::show(void){
cout <<_race_names[0];
}
foo::~foo(void){
}
and that is enough for Visual to throw linker error LNK2005 which says that :
Code:
foo.obj : error LNK2005: "char (* _race_names)[20]" (?_race_name@@3PAY0P@DA) already defined in stdafx.obj
D:\Projects\Fallout\Debug\main.exe : fatal error LNK1169: one or more multiply defined symbols found
Why not to implement it in foo.h file ? because in my project are few classes that uses this data so i thougt it should be stored in some external file and then just include it whenewer I need it ... I know that this idea could be crappy
IvaN