相关疑难解决方法(0)

g ++模板参数错误

我有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 ++不是那么宽容.代码有什么问题?

c++ templates g++

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

g++ ×1

templates ×1