David
David

Reputation: 11

Expected type specifier error gcc

I have the following code:

In the file "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;
};
}

and in the file "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;
};

and I get the following error

expected type-specifier before ‘TPixelSum_TraitFor’

expected ‘>’ before ‘TPixelSum_TraitFor’

at line

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

The code is compiled with g++ 4.8.1

Upvotes: 1

Views: 796

Answers (1)

Mateusz Grzejek
Mateusz Grzejek

Reputation: 12058

This code compiled with no errors under MSVC++ 11.0 U4. Only issue it was complaining about was undefined type specified as a base class:

TImageProcessor< T >

Are you sure this type is known in the scope of this file? I'm not fimiliar with GCC error messages, but this syntax:

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

is perfectly valid, so he probably complains about next line.

UPDATE:

I tested your code with g++ 4.8.1. I splitted content to two files and removed unknown types:

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()
{
}

Command: g++ -o test.o test.cpp

Result: OK, no error.

Upvotes: 2

Related Questions