这是一个模板<;国际…>;C++;可能的 我试图在C++中学习实现模板>代码>。当我将NTT(数论转换)代码更改为使用模板的代码时,如下所示: template <long long mod> struct NTT{ int x = 0; NTT(){ long long p = mod-1; while(!(p % 2)){ p >>= 1; ++x; } } const static long long root_pw = 1 << x; //(there is a function after this that also needs to read the value 'root_pw') }; signed main() { NTT<998244353> ntt1; vector<long long> a(ntt1::root_pw,0); } 模板结构NTT{ int x=0; NTT(){ 长p=mod-1; 而(!(p%2)){ p>>=1; ++x; } } const static long root_pw=1
您可以替换C++14函数这是一个模板<;国际…>;C++;可能的 我试图在C++中学习实现模板>代码>。当我将NTT(数论转换)代码更改为使用模板的代码时,如下所示: template <long long mod> struct NTT{ int x = 0; NTT(){ long long p = mod-1; while(!(p % 2)){ p >>= 1; ++x; } } const static long long root_pw = 1 << x; //(there is a function after this that also needs to read the value 'root_pw') }; signed main() { NTT<998244353> ntt1; vector<long long> a(ntt1::root_pw,0); } 模板结构NTT{ int x=0; NTT(){ 长p=mod-1; 而(!(p%2)){ p>>=1; ++x; } } const static long root_pw=1,c++,c++11,compiler-errors,fft,ntt,C++,C++11,Compiler Errors,Fft,Ntt,您可以替换C++14函数 template <long long mod> constexpr int f() { int x = 0; long long p = mod-1; while(!(p % 2)){ p >>= 1; ++x; } return x; } 模板 constexpr int f() { int x=0; 长p=mod-1; 而(!(p%2)){ p>>=1;
template <long long mod>
constexpr int f()
{
int x = 0;
long long p = mod-1;
while(!(p % 2)){
p >>= 1;
++x;
}
return x;
}
模板
constexpr int f()
{
int x=0;
长p=mod-1;
而(!(p%2)){
p>>=1;
++x;
}
返回x;
}
通过C++11版本:
template <long long p>
constexpr int f2()
{
return p % 2 ? 0 : 1 + f2<p / 2>();
}
template <long long mod>
constexpr int f()
{
return f2<mod - 1>();
}
模板
constexpr int f2()
{
返回p%2?0:1+f2();
}
模板
constexpr int f()
{
返回f2();
}
诸如此类
template <long long mod>
struct NTT{
constexpr static const long long root_pw = 1LL << f<mod>();
};
模板
结构NTT{
constexpr static const long long root_pw=1LL您可以替换C++14函数
template <long long mod>
constexpr int f()
{
int x = 0;
long long p = mod-1;
while(!(p % 2)){
p >>= 1;
++x;
}
return x;
}
模板
constexpr int f()
{
int x=0;
长p=mod-1;
而(!(p%2)){
p>>=1;
++x;
}
返回x;
}
通过C++11版本:
template <long long p>
constexpr int f2()
{
return p % 2 ? 0 : 1 + f2<p / 2>();
}
template <long long mod>
constexpr int f()
{
return f2<mod - 1>();
}
模板
constexpr int f2()
{
返回p%2?0:1+f2();
}
模板
constexpr int f()
{
返回f2();
}
诸如此类
template <long long mod>
struct NTT{
constexpr static const long long root_pw = 1LL << f<mod>();
};
模板
结构NTT{
constexpr static const long long root_pw=1LL不能使用非静态数据成员初始化静态数据成员。静态数据成员在任何对象(因此非静态成员)之前很久就被初始化在C++ 14中,CONTXPR函数最容易编写成与常规函数类似的。在C++ 11中,由于限制更多,所以更复杂。注意GCC在版本9和版本10上。如果允许,强烈考虑从4.9升级。不能使用非静态数据成员初始化静态数据成员。数据成员早于任何对象(因此非静态成员)初始化在C++ 14中,CONTXPR函数最容易编写成与常规函数类似的。在C++ 11中,由于限制更多,所以更复杂。注意GCC是在版本9和版本10上。如果允许,强烈考虑从4.9.升级。谢谢!但是,在我这么做之后,它说“ntt1不是类、名称空间或枚举”当我写到:NTT ntt1;vector a(ntt1::root_pw,0);你能帮我完成这部分吗?它应该是ntt1.root_pw
(这不是调用静态方法(尽管是实例)的常用方式)或使用ntt1=NTT;
(因此ntt1
是ALI类型而不是实例类)。非常感谢!!!但是,在我这么做之后,当我写:NTT ntt1;vector a(ntt1::root_pw,0);你能帮我完成这部分吗?它应该是ntt1.root_pw
(这不是调用静态方法(尽管是实例)的常用方式)或使用ntt1=NTT;
(因此,ntt1
是alis类型,而不是实例类)。