I’m a novice at compiling with g++. But it’s ok with the following code if i use visual studio.
template <typename ValueType>
class ExprBase {
private:
ExprBase () {}
protected:
ValueType value;
public:
explicit ExprBase (const ValueType& v) : value(v) {}
virtual Value<ValueType> operator () (const map<const char*, ValueType>& values) const {
return Value<ValueType>(ValueType(), "");
}
};
template <typename ValueType>
class Const : public ExprBase<ValueType> {
public:
Const (const ValueType& v) : ExprBase<ValueType>(v) {}
virtual Value<ValueType> operator () (const map<const char*, ValueType>& values) const {
return Value<ValueType>(value, "");
}
};
The error is: “‘value’ undeclared”. What do i’ve to correct to be able to compile with g++? thanks for help
You need to use
or
because the base is a dependent type in this instance (whereas value is a non-dependent name). Visual Studio is “helping” you by compiling code that’s non-standard (this is actually very unhelpful, because things then break when you compile the same code with g++).
For more information, see p.136-8 of C++ Templates: The Complete Guide by Vandevoorde and Josuttis.