错误:调用'function namel'没有匹配函数
error: no matching function for call to 'function namel'
我的最终目标是计算二次理想的幂,该二次理想使用 GMP 库在 C 中作为结构变量实现。
我得到了一个库(ANTL(,其中包含使用C++模板,命名空间和NTL的通用优化幂。此库对 NTL 类型ZZ_p等和基本类型(如长整型、浮点数等(执行幂运算。
我必须使用 ANTL 库来实现我的最终目标 - 计算理想C 结构变量的功效。由于我从未使用过模板和命名空间,因此我想实现基本mpz_t变量的强大功能,以了解一切工作原理。
现在,我有四个头文件 exp.hpp、expbin.hpp、impl.hpp、com.hpp 和一个主文件 exp.cpp如下所示 -
.COM。人乳酸
#ifndef GMPL_COM_H
#define GMPL_COM_H
#include <gmp.h>
namespace GMPL {
template < class T >
inline void assign(T C, const T A)
{
mpz_set(C, A);
}
template<class T>
void mul (T C, const T A, const T B)
{
mpz_mul(C, A, B);
}
template<class T>
void sqr (T C, const T A)
{
mpz_mul(C, A, A);
}
}
#endif // guard
经验。人乳酸
#ifndef EXP_H
#define EXP_H
#include "com.hpp"
namespace GMPL
{
template < class T >
class exp
{
public:
exp() {};
virtual ~exp() {};
virtual void power (T C, const T A, const NTL::ZZ & n) = 0;
};
} // GMPL
#endif // EXP_H
呵呵。人乳酸
#ifndef EXPBIN_H
#define EXPBIN_H
#include "exp.hpp"
namespace GMPL
{
template < class T >
class expbin : public exp<T>
{
public:
expbin() {};
~expbin() {};
void power (T C, const T A, const NTL::ZZ & n);
};
} // GMPL
// Unspecialized template definitions.
#include "impl.hpp"
#endif // EXPBIN_H
英普尔。人乳酸
using namespace GMPL;
//
// compute A^n using standard left-to-right binary method
//
template < class T >
void expbin<T>::power (T C, const T A, const NTL::ZZ & n)
{
assign(C,A);
for (register long i = NumBits(n)-2 ; i >= 0 ; i--)
{
sqr(C, C);
if (bit(n, i) == 1)
mul(C, C, A);
}
}
经验。.CPP
#include <NTL/lzz_p.h>
#include <gmp.h>
namespace GMPL {}
using namespace GMPL;
#include "expbin.hpp"
NTL_CLIENT
int main ()
{
// NTL variables
ZZ n;
// GMP variables
mpz_t aa;
mpz_t bb;
mpz_init(aa);
mpz_init(bb);
// generate random exponent of size 512 bits
RandomLen (n, 512); // NTL function
// initialize exponentiation classes
expbin<mpz_t> obj;
// compute a^n with available methods
obj.power (bb,aa,n);
// check and output results
gmp_printf("%Zd", bb);
}
当我尝试编译EXP 时。CPP使用(如Victor Shoup的NTL在线文档所述(
g++ -g -O2 -std=c++11 -pthread -march=native exp.cpp -o t -lntl -lgmp -lm
我收到以下错误消息-
$ g++ -g -O2 -std=c++11 -pthread -march=native exp.cpp -o t -lntl -lgmp -lm
In file included from exp.cpp:8:
In file included from ./expbin.hpp:46:
./impl.hpp:16:10: warning: 'register' storage class specifier is deprecated and
incompatible with C++1z [-Wdeprecated-register]
for (register long i = NumBits(n)-2 ; i >= 0 ; i--)
^~~~~~~~~
./impl.hpp:15:5: error: no matching function for call to 'assign'
assign(C,A);
^~~~~~
exp.cpp:28:9: note: in instantiation of member function
'GMPL::expbin<__mpz_struct [1]>::power' requested here
obj.power (bb,aa,n);
^
./com.hpp:16:17: note: candidate template ignored: deduced conflicting types for
parameter 'T' ('__mpz_struct *' vs. 'const __mpz_struct *')
inline void assign(T C, const T A)
^
In file included from exp.cpp:8:
In file included from ./expbin.hpp:46:
./impl.hpp:20:13: error: no matching function for call to 'mul'
mul(C, C, A);
^~~
./com.hpp:22:10: note: candidate template ignored: deduced conflicting types for
parameter 'T' ('__mpz_struct *' vs. 'const __mpz_struct *')
void mul (T C, const T A, const T B)
关于这些错误的孜孜不倦的谷歌搜索表明,在父类中必须有一个空的构造函数,但我已经有了它。
我知道编译语句是正确的,因为除此之外,使用 NTL 时没有其他工作。在这一点上,我没有想法来解决这个问题。提前谢谢。
编辑此问题已解决。我希望这个问题被关闭或删除。
一种解决方案是不为函数包装器使用模板。似乎只有一个模板参数是有意义的(即T
替换为mpz_t
(,因为模板参数必须与mpz_set
兼容。模板似乎是这项工作的错误工具。只需定义采用mpz_t
和const mpz_t
类型参数的包装器:
inline void assign(mpz_t C, const mpz_t A)
{
mpz_set(C, A);
}
您确实说过您想学习模板,但是在不适当的上下文中使用它们不会那么有帮助。而且您仍然拥有可供课程学习的模板。
话虽如此,我可以为您解释编译器消息。
警告:"寄存器"存储类说明符已弃用,并且 与 C++1z [-已弃用寄存器]
for (register long i = NumBits(n)-2 ; i >= 0 ; i--)
不兼容
这是一个很容易解决的问题。摆脱该行中的"注册"。它不再是性能优化。
错误:调用"分配"
assign(C,A);
没有匹配函数
[...]
注意:忽略候选模板:推断出冲突的类型 参数"T">
编译器无法确定在此函数调用中用作模板参数的内容。有两个函数参数,每个参数都暗示assign
的模板参数应该是什么。(这与expbin
的模板参数不同,即使两者都被命名为T
。当影响发生冲突时,这是一个问题。完成此操作的一种方法是指定您希望参数是什么,如
assign<T>(C, A);
这明确表明assign
的模板参数(在<
和>
之间给出(应该是expbin
的模板参数(在此上下文中T
的含义(。
注意:您定义的模板看起来可以正常工作,而无需像这样指定T
。但是,从技术上讲,mpz_t
是一个结构(而不仅仅是结构(的数组,用作参数的数组可能会衰减,这可能会导致类型混淆。
错误:调用"mul"没有匹配函数
mul(C, C, A);
注意:候选模板被忽略:推断出冲突的类型 参数"T">
相同(尽管在这种情况下有三个函数参数,因此推导出了三个T
候选者(。
mul<T>(C, C, A);
- "error: no matching function for call to"构造函数错误
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- 如何为 v8::P ersistent<v8::Function> 创建到 c++ 函数的包装器
- C++复制函数重载导致"must be a nonstatic member function"错误
- C++派生类重载函数(带有 std::function 参数)不可见
- 如何将函数指针从 std::function 传递到 Linux 克隆?
- 如何在跳过所有内部实现的同时跳转到 GDB 中 std::function 中的函数?
- 将函数的参数 - 签名从使用 'std::function<T>' 转换为模板参数类型
- C++:从重载函数转换为 std::function
- 仅当一个参数中未使用 std::function 时,模板函数替换才有效
- 使用 object 中的方法调用带有 std::bind 和 std::function.target 的 C 样式函数
- 插件:TypeError:addons.function() 不是一个函数
- 可变参数函数模板不能很好地使用 std::function 作为参数
- 将另一个类的成员函数传递到 std::function 参数中
- 如何从类成员函数返回指针,例如 size_t * class :: function(); 并使用类析构函数 ~size
- 创建函数变体向量时"No matching function for call"错误
- 在windows上使用ctypes在python中包装c++函数:function未找到
- 我所有的函数都有错误 C2084:函数'function'已经有一个主体