我已经搜索过这个问题但我找不到任何相关内容.有没有更好的方法在Google中查询这样的内容,或者任何人都可以提供链接或链接或相当详细的解释?谢谢!
编辑:这是一个例子
template< typename T, size_t N>
struct Vector {
public:
Vector() {
this->template operator=(0);
}
// ...
template< typename U >
typename boost::enable_if< boost::is_convertible< U, T >, Vector& >::type operator=(Vector< U, N > const & other) {
typename Vector< U, N >::ConstIterator j = other.begin();
for (Iterator i = begin(); i != end(); ++i, ++j)
(*i) = (*j);
return *this;
}
};
Run Code Online (Sandbox Code Playgroud)
此示例来自Google Code上的ndarray项目,而不是我自己的代码.
我有GetContainer()函数如下.
template<typename I,typename T,typename Container>
Container& ObjCollection<I,T,Container>::GetContainer()
{
return mContainer;
}
Run Code Online (Sandbox Code Playgroud)
当我使用这个方法如下
template<typename I,typename T>
T& DynamicObjCollection<I,T>::Insert(T& t)
{
GetContainer().insert(&t);
return t;
}
Run Code Online (Sandbox Code Playgroud)
我有错误.
error: there are no arguments to ‘GetContainer’ that depend on a template parameter,
so a declaration of ‘GetContainer’ must be available
error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of
an undeclared name is deprecated)
Run Code Online (Sandbox Code Playgroud)
它适用于MSVC,但g ++不是那么宽容.代码有什么问题?