C ++函数定义错误(参数传递)

时间:2013-10-13 18:26:20

标签: c++ function parameters parameter-passing

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

我的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)

1 个答案:

答案 0 :(得分: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 */
}

使用时,功能模板将实例化