e.proydakov
e.proydakov

Reputation: 602

Compile error with a template when building with GCC but not MSVC

On expression:

typedef RDOCalcUnary<RDOValue, (&RDOValue::operator-), OperatorType::OT_ARITHM> RDOCalcUMinus;

gcc shows the following errors:

error: ‘rdoRuntime::RDOValue::operator-’ cannot appear in a constant-expression

error: ‘&’ cannot appear in a constant-expression

error: template argument 2 is invalid

error: invalid type in declaration before ‘;’ token

Under Windows the MSVC compiler compiles the code without errors.

What's the problem? How do I fix this?

template <typename ret_type, ret_type (RDOValue::*pOperator)() const, typename OperatorType::Type CalcType>
class RDOCalcUnary: public RDOCalcUnaryBase
{
friend class rdo::Factory<RDOCalcUnary<ret_type, pOperator, CalcType> >;
public:
    enum { calc_type = CalcType };
    typedef ret_type (RDOValue::*value_operator)() const;

    static RDOSrcInfo     getStaticSrcInfo(CREF(RDOSrcInfo::Position) position, CREF(LPRDOCalc) pUnaryCalc);
    static value_operator getOperation    ();

protected:
    RDOCalcUnary(CREF(RDOSrcInfo::Position) position, CREF(LPRDOCalc) pOperation);

private:
    REF(RDOValue) doCalc(CREF(LPRDORuntime) pRuntime);
};

Upvotes: 2

Views: 349

Answers (1)

David Eles
David Eles

Reputation: 26

When you do the typedef don't use brackets:

typedef RDOCalcUnary<RDOValue, &RDOValue::operator-, OperatorType::OT_ARITHM> RDOCalcUMinus;

It works to me.

Upvotes: 1

Related Questions