Share via

inherit std::vector using constructors

Anonymous
2017-08-14T13:20:47+00:00

This question must have been asked more than once, but I cannot find a working answer anywhere.  The goal is to create a class based on the std::vector class and use the range checking in addition. The code, literally taken from a book by Stroustrup (sp?), is below. I can't get it to work, it won't compile on VS2013.  It is the statetement 'using vector<T>::vector;' that is the culprit.

Error 1 error C2886: 'vector<T,std::allocator<_Ty>>' : symbol cannot be used in a member using-declaration c:\insightmontrex\ver12.0\src\anytest.cpp 8 1 AnyTest

Error 3 error C2664: 'Vector<int>::Vector(const Vector<int> &)' : cannot convert argument 1 from 'int' to 'const Vector<int> &' c:\insightmontrex\ver12.0\src\anytest.cpp 17 1 AnyTest

 Does anyone know how to handle this properly?

#include<vector>

usingstd::vector;

template<typenameT>

classVector : publicstd::vector<T>

{

public:

usingvector<T>::vector; // inherit constructors***

T& operator { returnvector<T>::at(i); } // range-checked

constT& operator const{ returnvector<T>::at(i); } // for const objects;

};

intmain()

{

Vector <int> V(5);

}

Windows for home | Previous Windows versions | Apps

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-10-23T23:00:49+00:00

Hi Henk,

You concern regarding the usage Visual Studio 2013 app is best being handled in MSDN forums. Here's the link.

Do let us know if you have any other concerns.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful