Okay here's the deal w/inheriting std::vector and the template arguments:
Case 1:
Case 2:Code:#include <vector> class SizeVector : public std::vector<int>{ // template parameter is defined }; int main(){ SizeVector szvec; // template parameter not needed return 0; }
So it depends on what you need your class to do I guess.Code:#include <vector> template <typename T> class SizeVector : public std::vector<T>{ // template parameter ambiguous }; int main(){ SizeVector<int> szVec; // template parameter needed return 0; }
Here's an example of how to do this in SizeVector's initialization list:
Code:#include <iostream> #include <vector> template <typename T> class SizeVector : public std::vector<T> { public: SizeVector<T>() : std::vector<T>() {} // Default constructor SizeVector<T>( const std::vector<T>& rhs ) // Alternate constructor copies an existing std::vector : std::vector<T>( rhs ) {} }; int main(){ std::vector<int> aVector; aVector.push_back( 5 ); SizeVector<int> szVector( aVector ); std::cout << szVector[0] << "\n"; return 0; }


CornedBee