// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <map>
#include <string>
#include <memory>
template<class T >
struct ExpressionTrait ;
class IA
{
public:
virtualvoid func() = 0;
};
class A : public IA
{
public:
void func()
{
std::cout << "sdfdsf" << std::endl;
}
};
template<>
struct ExpressionTrait <A >
{
typedef IA parentType;
staticconstint max = 100;
staticconstint min = 1;
};
template<typename ExpressionObject >
class ExpressionFactory
{
public:
static ExpressionFactory<ExpressionObject >& Instance()
{
static ExpressionFactory<ExpressionObject > instance;
return instance;
}
typedef std:: map< int, int> RegisterCreatorMap;
template< typename T>
void registerCreator()
{
std::cout << "sdfdsf" << std::endl;
creatorMap_.insert(std::make_pair( ExpressionTrait<T >::max,
ExpressionTrait<T >::min));
}
int createExpression( int type)
{
typename RegisterCreatorMap::iterator typeIter = creatorMap_.find(type);
if (typeIter != creatorMap_.end())
{
int creator = typeIter ->second;
return creator;
}
return -1;
}
RegisterCreatorMap creatorMap_;
};
template<class T >
struct ExpressionFactoryAutoRegister
{
ExpressionFactoryAutoRegister()
{
// This line cannot be compiled
ExpressionFactory<typename ExpressionTrait<T >::parentType >::Instance().registerCreator<T>();
}
};
int _tmain (int argc , _TCHAR * argv [])
{
ExpressionFactoryAutoRegister<A> temp;
//ExpressionFactory<IA>::Instance().registerCreator<A>();
int a = ExpressionFactory<IA >::Instance().createExpression(100);
getchar();
return 0;
}
I can compile this code in VS2015, but cannot compile by GCC, the error message is :
ExpressionFactory.hpp:156:107: error: expected primary-expression before '>' token
ExpressionFactoryT<typename ExpressionTrait<T >::parentType >::Instance().registerCreator<T>();
^
/containers/lewguo/lewguo/rootfs/home/lewguo/s/scfupgrade/src/rules/DependenceModParamConditionalExpressionRelative/ExpressionFactory.hpp:156:109: error: expected primary-expression before ')' token
ExpressionFactoryT<typename ExpressionTrait<T >::parentType >::Instance().registerCreator<T>();