|
From: Георгий Ф. <ab...@ma...> - 2011-09-16 16:47:55
|
Hello. When I compile this code
#include <cstdlib>
#include <iostream>
template <class Type> class Number {
protected:
Type value;
public:
Number(Type valueV) {
value = valueV;
}
virtual Type getValue() {
return value;
}
};
template <class Type> class Sqr : public Number<Type> {
public:
Sqr(Type valueV) : Number<Type>(valueV) {}
Type getValue() {
return value * value;
}
};
int main(int argc, char** argv) {
Sqr<int> obSqrInt (20);
std::cout << "obSqrInt.getValue() " << obSqrInt.getValue() << "\n";
return 0;
}
in MinGw, I get
E:\Test>g++ -o a test.cpp
test.cpp: In member function 'Type Sqr<Type>::getValue()':
test.cpp:21:16: error: 'value' was not declared in this scope
When I compile and run this code in Visual c++, I get
obSqrInt.getValue() 400
Explain me, please, why MinGW not compile this code.
With best reguards, George, from Kiev
|