# How to use a custom class without adding it to the project?

This topic is 2888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working through a DirectX book and I want to use one of the author's supplied classes - GameTimer, for the timer in my code. Rather than find it and add it to my project every time, how could I say #include <GameTimer.h> and have the class just work? I tried adding the folder with the header and source files to the VC++ Directories in the settings page (I'm using VS2008), so the compiler won't complain about finding the file - that seems to work (Intellisense also works for the class, so it's seeing the the class), but whenever I try to compile, it gives me a linker error: main.obj : error LNK2019: unresolved external symbol "public: __thiscall GameTimer::GameTimer(void)" (??0GameTimer@@QAE@XZ) referenced in function "void __cdecl dynamic initializer for 'timer''(void)" (??__Etimer@@YAXXZ) fatal error LNK1120: 1 unresolved externals Any tips here?

##### Share on other sites
That class would need to have a library, source file or something to link the code with. Just a header file;

MyClass.h
------------------------------------
#ifndef _MyClass_h_#define _MyClass_h_class MyClass{private:   int m_iVar;public:   int DoSomething(int what);};#endif`

Does nothing itself except define how the MyClass interface is. So there must be either a library; static (lib) or dynamic (dll) to link with your project, or some Source File that must be added to each project using the implementation.

So basically, by including the header your project knows what MyClass _can_ do, but it does not know how (or more appropriately where) it does it, so MyClass will not work. (Hence the linker errors).