With the code below, that I have deducted the part with problem from a huge project, is giving me expected primary-expression error with gcc 7.1, whereas it compiles me with, for example, gcc <= 6.1 (the versions between I did not try yet).
Maybe it is because of some new definitions, but I could not find it.
Here is the code:
basesm.h
#ifndef BASESM_H
#define BASESM_H
#include "statemachine.h"
class IEVD
{
};
template<U16 SIZE>
class CEventDispatcher : public IEVD
{
public:
template<U16 INDEX> IState* GSM(void) { return _xSM.GSM<INDEX>(); }
CRootSM<SIZE> _xSM;
};
#endif // BASESM_H
statemachine.h
#ifndef STATEMACHINE_H
#define STATEMACHINE_H
#include "types.h"
class IState
{
public:
IState(void)
{
}
};
class CState : public IState
{
public:
};
template<U16 SIZE> class CRootSM
{
public:
CRootSM(void) : _xStates()
{
for(U16 u16State = 0; u16State < SIZE; ++ u16State)
{
_xStates[u16State] = new CState();
}
}
template<U16 INDEX>
IState* GSM(void)
{
static_assert(INDEX < SIZE, "Index overrun.");
return _xStates[INDEX];
}
IState* _xStates[SIZE];
};
#endif // STATEMACHINE_H
types.h
#ifndef TYPES_H
#define TYPES_H
typedef unsigned short U16;
#endif // TYPES_H
winnetwork.cpp
#include "basesm.h"
#include "statemachine.h"
main.cpp
int main()
{
return 0;
}
Error:
error: expected primary-expression before ')' token template<U16 INDEX> IState* GSM(void) { return _xSM.GSM<INDEX>(); }