template模板在Windows和Linux下的不同用法

编程知识 更新时间:2023-04-06 22:35:44

以下内容说明:windows是采用VS2010,Linux下是使用Eclipse 20140224-0627


一、子类继承模板基类的时候,只能继承一个指定的实例化,在子类的初始化列表中的实例化信息(本例中为<string, int, double>),在Windows下可以省略,在Linux下不可以省略,例子如下:


class CFFundbriefInfo

    : public ConfigFileBase<string, int, double>
{
public:
    CFFundbriefInfo():ConfigFileBase <string, int, double>(“test”, 10, 20.9){};
    CfgTypeEnum GetCfgType() { return 0; };
    const char* GetCfgName() { return "test"; };

};

报错信息如下:

error: class ‘CFCurrencyInfoFile’ does not have any field named ‘ConfigFileBase’


二、在使用模板的std的容器的迭代器时,Windows下定义迭代器可以不需要在前面写typename,Linux下的Eclipse必须要写,否则编译不过。


for(typename list<toT_>::const_iterator it = myList->begin(); it != myList->end(); ++it)

报错信息如下:

error: dependent-name ‘std::list::const_iterator’ is parsed as a non-type, but instantiation yields a type

error: expected `;' before ‘it’

error: ‘it’ was not declared in this scope


三、模板类和其成员方法定义相同的typaname问题,windows下可以同名,Linux下不能同名,同名会报编译错误,代码如下:

template<class keyT_, class valueT_, class toT_>
class ConfigFileBase : public IInitFile
{
protected:
    template<class fromT_, class toT_>
    bool ChangeBaseType(const fromT_* fromBuf, toT_* toBuf)
    {
        ...
        return true;
    }
}

报错信息如下:

error: declaration of ‘class toT_’

error:  shadows template parm ‘class toT_’

更多推荐

template模板在Windows和Linux下的不同用法

本文发布于:2023-04-06 22:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/de436cc58ff96b3b7076680bc602b70c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   template   Linux   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 51163文章数
  • 14阅读数
  • 0评论数