2014-02-15 48 views
1

我有以下代码:预期类型说明符错误GCC

在文件 “的defs.h”

namespace ABCD 
{ 
template < typename T > 
class TPixelSum_TraitFor 
{ 
    public: 
     typedef double AccumType; 
}; 


template <> 
class TPixelSum_TraitFor<MonochromeImage::PixelType> 
{ 
    public: 
     typedef /*unsigned*/ long AccumType; 
}; 
} 

,并在文件中 “GraphicLibrary.h”

#include "Defs.h" 

using namespace ABCD; 
using namespace std; 

template < typename T, typename ACC_TRAIT = TPixelSum_TraitFor<T> > 
class SumImage : public TImageProcessor<T> 
{ 
    public: 

     typedef typename ACC_TRAIT::AccumType AccumType; 

    private: 

     AccumType fSum; 
}; 

和我收到以下错误

'T之前的预期类型说明符PixelSum_TraitFor”

预期 '>' 前 'TPixelSum_TraitFor'

在线路

模板<类型名称T,类型名ACC_TRAIT = TPixelSum_TraitFor < T>>

的代码是用g ++编译4.8.1

回答

1

此代码在MSVC++ 11.0 U4下编译时无错误。唯一的问题有人抱怨是未定义的类型指定为基类:

TImageProcessor<T> 

你确定这种类型在此文件的范围内已知的?我不熟悉GCC错误信息,但是这个语法:

template < typename T, typename ACC_TRAIT = TPixelSum_TraitFor<T> > 

是完全有效的,所以他可能会抱怨下一行。

更新:

我用g ++ 4.8.1测试了你的代码。 我分裂内容两个文件并删除未知类型:

test.h

namespace ABCD 
{ 
    template < typename T > 
    class TPixelSum_TraitFor 
    { 
    public: 
    typedef double AccumType; 
    }; 

    template <> 
    class TPixelSum_TraitFor< long /*MonochromeImage::PixelType*/ > //MonochromeImage is unknown 
    { 
    public: 
    typedef long AccumType; 
    }; 
} 

test.cpp

#include "test.h" 

using namespace ABCD; 
using namespace std; 

template < typename T, typename ACC_TRAIT = TPixelSum_TraitFor<T> > 
class SumImage //: public TImageProcessor<T> -> TImageProcessor is also unknown 
{ 
public: 
    typedef typename ACC_TRAIT::AccumType AccumType; 

private: 
    AccumType fSum; 
}; 

int main() 
{ 
} 

命令: g++ -o test.o test.cpp

结果:OK,没有错误。

+0

Upvoted的答案,我也无法重现此错误。 – Ali

+0

这可能是由于未知类型的注释。但我只是在猜测,GCC是我不太熟悉的东西。 –

+0

那么,我们不应该猜测,他应该发布一个[SSCCE](http://sscce.org/),以便我们可以诊断问题。我也投票结束这个问题。 – Ali