I have the following code:
What I'm trying to do inside the "VectorOfPairs(unsigned int)" constructor is what we would write in Java as "super(length)". But for some reason, it gives me a compilation error:Code:#include <iostream> #include <utility> using namespace std; template<typename T> class Vector { public: Vector(unsigned int length = 10) { } }; template<typename P, typename Q> class Pair { }; template<typename P, typename Q> class VectorOfPairs : public Vector<Pair<P, Q> > { public: VectorOfPairs(unsigned int length = 10) { Vector<Pair<P, Q> >::Vector(length); } }; int main() { VectorOfPairs<int, int> v; return 0; }
It seems to treat ` Vector<Pair<P, Q> >::Vector' as a type. But in reality, the type is ` Vector<Pair<P, Q> >', while the '::Vector' part is the constructor.Code:test.cpp: In constructor `VectorOfPairs<P, Q>::VectorOfPairs(unsigned int) [with P = int, Q = int]': test.cpp:26: instantiated from here test.cpp:21: error: dependent-name ` Vector<Pair<P, Q> >::Vector' is parsed as a non-type, but instantiation yields a type test.cpp:21: note: say `typename Vector<Pair<P, Q> >::Vector' if a type is meant
So my question is: is there anyway to tell the compiler that Vector<Pair<P,Q> > is the type?



LinkBack URL
About LinkBacks



air<int, int> > ? 