Reputation: 3
I'am newbie in c++, and i'm trying to write an additional template which contains type char or type int. After that I want to use this template in other template to select the type of data, depending of input data padding.
template <bool isPadding>
class PaddingTemplate;
template <>
class PaddingTemplate<false>
{
public:
typedef char Type;
};
template <>
class PaddingTemplate<true>
{
public:
typedef int Type;
};
template <class T, bool Padding = ((sizeof(T) % sizeof(int)) == 0)>
class ObjectComparator
{
private:
typedef PaddingTemplate<Padding> PaddingTrick;
typename PaddingTrick::Type DataType;
DataType Shadow[sizeof(T) / sizeof(DataType)];
};
I get this compiler error
How to solve the problem and automate the choice of data type depending on data padding?
Upvotes: 0
Views: 185
Reputation: 14614
DataType
isn't actually a type. It's a instance of PaddingTrick::Type
, which is why the next line is giving you an error. You need to do:
typedef typename PaddingTrick::Type DataType;
Upvotes: 4