I have a class that houses a ID3D11Device
member that I'd like to make static
, since for now, I want the ID3D11Device
to be accessed by multiple Entity
class instances. The problem is, I'm unable to access the Direct3D
class, housing the ID3D11Device
static member outside of it's object without directly instantiating the Direct3D
class.
Since multiple classes inherit from the Direct3D
class (Which in turn inherits from a WindowsClass
for hwnd
detail), I'd like to keep it as a base class, as to keep access with all classes inheriting from Direct3D
as this example proposes:
class Direct3D: WindowsClass{
public:
Direct3D();
~Direct3D();
static ID3D11Device* Device;
}
And an inherited class:
class EntityType: Direct3D{
public:
EntityType();
~EntityType();
void SomeDeviceDependentFunction();
}
Where the member is defined as:
void EntityType::SomeDeviceDependentFunction(){
//Perform some action calling Direct3D::Device.
}
Note that the class Direct3D
is defined in Direct3D.h
, EntityType
is defined in EntityType.h
, and so on. So everything looks gravy in concept until I go to compile and receive the dreaded error:
Error 52 error LNK2001: unresolved external symbol "public: static struct ID3D11Device * Direct3d::Device" (?Device@Direct3d@@2PAUID3D11Device@@A) C:\Us...tions.obj Win32Project1
And:
Error 40 error LNK2005: "class std::vector<struct IndexVertexKey,class std::allocator<struct IndexVertexKey> > Geometry" (?Geometry@@3V?$vector@UIndexVertexKey@@V?$allocator@UIndexVertexKey@@@std@@@std@@A) already defined in D3DPipeline.obj C:\Use...nagement.obj Win32Project1
(Please note that the compile errors here do not relate directly to the examples given above, but are caused by them.)
To summarize, how can I control inherited classes where they are loosely coupled, (object to object) or where I can reference includes safely without dying of cross-references?