I omitted #include "stdafx.h in each file.
stdafx.h (precompiled headers)
#include a.h
#include b.h
class stuff;
stuff * s
a.h
class thing{float f; void fun()};
a.cc
void thing::fun(){}
thing::thing():
f(b->f) {} // lnk 2005 linking error
b.h
struct stuff
{
float f;
thing * t;
};
b.cc
stuff::stuff(): f(3.4) { t = new thing; }
main.cc
int main()
{
s = new stuff;
s -> fun();
}
As you can see, I try to access s which is predeclared in stdafx.h
I’m doing this design so I don’t have to rely on singletons (I have one main class which I want to access in other smaller objects)
Do i need to use the extern keyword in some way ? Is the precompiled header causing problem ?
solved it by redesigning code. C++ is not very much clean to use.