是否可以转发声明一个使用默认参数的类而不指定或知道这些参数?
例如,我想boost::ptr_list< TYPE >在Traits类中声明一个,而不将整个Boost库拖动到包含特征的每个文件中.我想声明
namespace boost { template<class T> class ptr_list< T >; },但这不起作用,因为它与真正的类声明不完全匹配:
template < class T,
class CloneAllocator = heap_clone_allocator,
class Allocator = std::allocator<void*>
>
class ptr_list { ... };
Run Code Online (Sandbox Code Playgroud)
我的选择只是与它一起生活或boost::ptr_list< TYPE, boost::heap_clone_allocator, std::allocator<void*>在我的特质课程中指定吗?(如果我使用后者,我想也必须转发声明boost::heap_clone_allocator和包含<memory>,我想.)
我查看了Stroustrup的书,SO和其他互联网,但没有找到解决方案.通常人们担心不包括STL,解决方案是"只包括STL标题".但是,Boost是一个更大规模和编译器密集型的库,因此除非我绝对必须,否则我更愿意将其删除.
使用Visual C++ 2010,我对以下代码有一个奇怪的编译警告:
#include <iostream>
class test
{
public:
template<class obj>
class inner
{
private:
// Line 11:
template<int index, bool unused = true> struct AttributeName;
private:
template<bool b>
struct AttributeName<0,b>
{
static inline const char* get()
{
return "prop";
}
};
public:
typedef AttributeName<0> propname;
};
typedef inner<test> description;
};
int main()
{
test t;
std::cout << test::description::propname::get(); // Line 32
return 0;
}
Run Code Online (Sandbox Code Playgroud)
警告:
file.cpp(11) : warning C4348: 'test::inner<obj>::AttributeName' : redefinition of default parameter : parameter 2 (with …Run Code Online (Sandbox Code Playgroud)