Witam,
Walczę cały dzień z VS nie mogąc uzyskać dostępu do zmiennych globalnych z 2 różnych Form.
Plik Form1.h (główna) - fragment
.#include <vector>
.#include "toDoForm.h"
.#include "globalVar.h"
Plik globalVar.h
.#ifndef NAMESPACE_FOO
.#define NAMESPACE_FOO
.#include <vector>
using namespace std;
namespace Foo
{
vector <short int="int"> vA;
}
.#endif
Do tej pory wszystko działa.
Kiedy do pliku toDoForm.h (2 formatka) dodam:
.#include "globalVar.h"
mam taki efekt:
toDoForm.obj : error LNK2005: "class std::vector<short,class std::allocator<short> > Foo::vA" (?vA@Foo@@$$Q3V?$vector@FV?$allocator@F@std@@@std@@A) already defined in Task.obj
Visual Studio 2010\Projects\Task\Debug\Task.exe : fatal error LNK1169: one or more multiply defined symbols found
Kiedy w globalVar.h dodam extern:
extern vector <short int="int"> vA;
Mam:
Task.obj : error LNK2020: unresolved token (0A000047) "class std::vector<short,class std::allocator<short> > Foo::vA" (?vA@Foo@@$$Q3V?$vector@FV?$allocator@F@std@@@std@@A)
1>Task.obj : error LNK2001: unresolved external symbol "class std::vector<short,class std::allocator<short> > Foo::vA" (?vA@Foo@@$$Q3V?$vector@FV?$allocator@F@std@@@std@@A)
1>Visual Studio 2010\Projects\Task\Debug\Task.exe : fatal error LNK1120: 2 unresolved externals
Czy ktoś wie czemu tak się dzieje, googlowałem, ale nic nie rozwiązało moich problemów. Nadal nie wiem gdzie robię błąd.