0

我试图调用我的模板化函数但没有成功:(

我的 memaddr.h:

#ifndef __MEM_ADDR_WRITER__
#define __MEM_ADDR_WRITER__

#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>

namespace MemAddr {

    template <typename WRITABLE>
    int WriteMemoryAddress(const char* process, unsigned long address, WRITABLE value);

}

#endif

来电:

byte value = 0xEB;
MemAddr::WriteMemoryAddress("jamp.exe", 0x004392D2, value);

错误信息:

undefined reference to `int MemAddr::WriteMemoryAddress<unsigned char>(char const*, unsigned long, unsigned char)`

答:需要在标题中定义模板.. (@Shaggi)

4

1 回答 1

0

函数模板

template <typename WRITABLE>
int WriteMemoryAddress(const char* process, unsigned long address, WRITABLE value);

没有定义。在头文件 (memaddr.h) 中包含其定义:

template <typename WRITABLE>
int WriteMemoryAddress(const char* process, unsigned long address, WRITABLE value)
{
    /* do something */
}

函数模板将在您使用时实例化一次。

于 2013-10-13T18:29:33.793 回答