提升::池中不需要模板参数

No template parameters needed in boost::pool

本文关键字:参数 提升 不需要      更新时间:2023-10-16

声明boost::poor如下。

boost::pool<> Obj();

我很好奇如何制作一个不需要模板参数而只需要<>的类模板?

我试着把它作为助推::pool.hpp和pool.fwd.hpp.中的pool

template<class T>
class Fakepool { };  // pool.hpp
template<class T = int>
class Fakepool;   // boost::pool's declaration in poolfwd.hpp 
int main()
{
    Fakepool<float> a;
    Fakepool<> a2; // Can't do this with only <>
}//main()

提前感谢!

这就是您想要的吗?

template<class T = int>
class Fakepool { };
int main()
{
    Fakepool<float> a; // Use float
    Fakepool<> a2; // Default as int
}

你也可以这样做(我想这就是你当时的想法)。这里的关键字是default template arguments。然而,在您的示例中,您在声明类之前定义了它,这就是问题所在。

template<class T = int>
class Fakepool; 
template<class T>
class Fakepool { }; 
int main()
{
    Fakepool<float> a;
    Fakepool<> a2;
}