Unresolved External Symbol?

Hi,
Below is the source:

Memory.h:
#include <Windows.h>


class Memory
{
public:
	template<class T>
	BOOL WriteSingle(HANDLE, unsigned long, T*);
	template<class T>
	BOOL Write(HANDLE, unsigned long, T*, SIZE_T);
	template<class T>
	T ReadByte(HANDLE, unsigned long);
	template<class T>
	T ReadInt32(HANDLE, unsigned long);

};
template<class T>
BOOL Memory::WriteSingle(HANDLE hProcess, unsigned long address, T*content)
{
	return WriteProcessMemory(hProcess,LPVOID(address),(LPCVOID)content,sizeof(T),NULL);
}
template<class T>
BOOL Memory::Write(HANDLE hProcess, unsigned long address, T*content, SIZE_T length)
{
	return WriteProcessMemory(hProcess,LPVOID(address),(LPCVOID)content,length,NULL);
}
template<class T>
T ReadByte(HANDLE hProcess, unsigned long address)
{
	T out;
	ReadProcessMemory(hProcess,LPCVOID(address),&out,sizeof(T),NULL);
	return out;
}
template<class T>
T ReadInt32(HANDLE hProcess, unsigned long address)
{
	T out;
	ReadProcessMemory(hProcess,LPCVOID(address),&out,4,NULL);
	return out;
}

Open in new window


When using it in my application (including "Memory.h") as such:
Memory MemoryC;
DWORD value = MemoryC.ReadInt32<DWORD>(hProcess,addr);

Getting this error:
Error      5      error LNK2019: unresolved external symbol "public: int __thiscall Memory::ReadInt32<int>(void *,unsigned long)" (??$ReadInt32@H@Memory@@QAEHPAXK@Z) referenced in function "unsigned long __cdecl read(void)" (?read@@YAKXZ)      


I don't know the issue. I know that this error typically occurs when you have a declaration without a definition, but I do have definitions for the functions!

Help would be greatly appreciated

Thank you!
stevedellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Your templating syntax seems to be a bit off, did you mean

#include <Windows.h>


template<typename T> 
class Memory
{
public:
	
	BOOL WriteSingle(HANDLE, unsigned long, T*);
	
	BOOL Write(HANDLE, unsigned long, T*, SIZE_T);
	
	T ReadByte(HANDLE, unsigned long);
	
	T ReadInt32(HANDLE, unsigned long);

};

template<typename T>
BOOL Memory<T>::WriteSingle(HANDLE hProcess, unsigned long address, T*content)
{
	return WriteProcessMemory(hProcess,LPVOID(address),(LPCVOID)content,sizeof(T),NULL);
}
template<typename T>
BOOL Memory<T>::Write(HANDLE hProcess, unsigned long address, T*content, SIZE_T length)
{
	return WriteProcessMemory(hProcess,LPVOID(address),(LPCVOID)content,length,NULL);
}
template<typename T>
T Memory<T>::ReadByte(HANDLE hProcess, unsigned long address)
{
	T out;
	ReadProcessMemory(hProcess,LPCVOID(address),&out,sizeof(T),NULL);
	return out;
}
template<typename T>
T Memory<T>::ReadInt32(HANDLE hProcess, unsigned long address)
{
	T out;
	ReadProcessMemory(hProcess,LPCVOID(address),&out,4,NULL);
	return out;
}

void main ()
{
        HANDLE hProcess = 0;
        unsigned long addr = 0;
        Memory<DWORD> MemoryC;
        DWORD value = MemoryC.ReadInt32(hProcess,addr);
}

Open in new window

?

(compiles fine here)
0
sarabandeCommented:
if you don't implement a member function in the class definition itself but outside of the class or in a cpp file, then you have to add the class scope

 template<class T> T Memory::ReadInt32(HANDLE hProcess, unsigned long address)

without the class scope the implementation is a global function and the linker complains that it doesn't find an implementation of Memory::ReadInt32.same errors would apply for the other template memory functions.

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sarabandeCommented:
Your templating syntax seems to be a bit off
actually it is quite ok, to have template member functions instead of a template class with a lot of template types.

especially with streaming operations as it is here you can use the same Memory object but use different template types for the functionality. moreover, you can put Memory objects for different data types into the same (template) container what is not possible if a template class was instantiated with different types.

Sara
0
stevedellAuthor Commented:
Great it's working now thanks very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.