以下内容说明: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下的不同用法