【发布时间】:2020-03-11 21:22:08
【问题描述】:
我已经声明了一个类模板:
template <typename DeallocFunction, typename CryptoObject>
class CryptoDeallocator
{
uint32_t (*DeallocFunc)(CryptoObject*);
CryptoObject *ObjectToDealloc;
public:
CryptoDeallocator(DeallocFunction i_p_func, CryptoObject *i_st_CryptoObject)
{
DeallocFunc = i_p_func;
ObjectToDealloc = i_st_CryptoObject;
}
~CryptoDeallocator()
{
if ((ObjectToDealloc != NULL) && (DeallocFunc != NULL))
{
DeallocFunc(ObjectToDealloc);
}
}
};
在我的代码的其他地方,我定义了一个具有以下原型的函数:
uint32_t nrf_crypto_ecc_private_key_free(nrf_crypto_ecc_private_key_t * p_private_key);
我尝试使用以下方法创建我的 CryptoDeallocator 类的实例:
nrf_crypto_ecc_private_key_t st_OwnPrivateKey;
CryptoDeallocator<uint32_t(*nrf_crypto_ecc_private_key_free)(nrf_crypto_ecc_private_key_t*), nrf_crypto_ecc_private_key_t> st_CryptoDeallocator(nrf_crypto_ecc_private_key_free, &st_OwnPrivateKey);
但我在 IAR 中收到编译错误:错误 [Pe018]:预期为“)”。
我应该使用什么正确的语法来实例化 CryptoDeallocator 类对象?
【问题讨论】:
标签: c++ function-pointers class-template