![](/img/trans.png)
[英]Static private function with templated type as a default argument in C++
[英]C++ function template argument with templated type struct woes
这段代码无法解释:
struct sometype
{
template <typename T>
T* get() { return nullptr; }
};
template <typename T>
struct anothertype
{
#if 1
template <typename T2> struct some_wrapper { typedef T2 type; };
typedef typename some_wrapper<sometype>::type thetype;
#else
typedef sometype thetype;
#endif
typedef thetype* Ptr;
Ptr m_ptr;
T* get() { return m_ptr->get<T>(); }
};
如果我将#if
参数更改为0,则会以某种方式修复。 有人可以解释一下吗? 请注意,显然毫无意义的some_wrapper
实际上在我的实际代码中做了一些有用的事情。
我正在使用g ++ 4.7.1和-fstd=gnu++11
,错误如下(指向我声明anothertype<T>::get
:
error: expected primary-expression before '>' token
error: expected primary-expression before ')' token
用你所有的typedef很难说,但是你需要下注:
m_ptr->template get<T>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.