S
Student
Why is the following code, which used to compile fine some years ago,
not compiling anymore?
g++ test.cpp
test.cpp: In member function ‘int D<T>::Size()’:
test.cpp:35: error: ‘v’ was not declared in this scope
test.cpp:35: error: ‘k’ was not declared in this scope
// test.cpp
template <typename T = int>
class B
{
public:
int v, k;
B(int Av, int Ak)
{
v = Av;
k = Ak;
}
virtual int Size() = 0;
//...
};
template <typename T = int>
class D : public B<T>
{
public:
D(int Av, int Ak) : B<T>(Av, Ak)
{
}
int Size()
{
return v * k;
}
};
int main(int argc, char* argv[])
{
D<long> C(10, 2);
//...
return 0;
}
not compiling anymore?
g++ test.cpp
test.cpp: In member function ‘int D<T>::Size()’:
test.cpp:35: error: ‘v’ was not declared in this scope
test.cpp:35: error: ‘k’ was not declared in this scope
// test.cpp
template <typename T = int>
class B
{
public:
int v, k;
B(int Av, int Ak)
{
v = Av;
k = Ak;
}
virtual int Size() = 0;
//...
};
template <typename T = int>
class D : public B<T>
{
public:
D(int Av, int Ak) : B<T>(Av, Ak)
{
}
int Size()
{
return v * k;
}
};
int main(int argc, char* argv[])
{
D<long> C(10, 2);
//...
return 0;
}