简体   繁体   English

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

[英]C++ function definition error (parameter passing)

I'm trying to call my templated function with no success :( 我试图调用我的模板函数没有成功:(

My 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

The call: 电话:

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

Error Message: 错误信息:

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

Answer: Templates needs to be defined in headers.. (@Shaggi) 答:模板需要在标题中定义。.(@Shaggi)

The function template 功能模板

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

is not defined. 没有定义。 Include its definition in the header file (memaddr.h): 在头文件(memaddr.h)中包含其定义:

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

The function template will be instantiated once when you use it. 使用该功能模板后,将对其实例化一次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM