I am currently working on implementing the constructor function for the vector class(my professor said that we can leave out anything that uses an allocator). I used the reference website that my professor gave us to determine the format of the function: http://www.cplusplus.com/reference/stl/vector/vector/
I am getting some errors in my function. Two of the errors are:
syntax error: identifier ‘size_type’
‘value’ : undeclared identifier
Any idea why I would be getting these errors? Here is my code:
explicit vector (size_type n, const T& value= T())
{
my_vect=new int x[2*n];
for(int i=0; i<n; i++)
{
vect[i]=value;
length++;
}
}
If you define your class in an .h file, then the
= T()is the default value. When you implement the method in the .cpp or .cc file, you leave out the default value.size_type is not in global scope it seems, so you need to use the resolution operator to give it correct scope. It appears to be
std::string::size_type. This is probably just a typedef forsize_t. I see size_type in the STL containers, but I’ve never used it when creating my own classes.Also, as Dietmar Kühl mentioned, when using C++ templates, you need to decorate everything with
template <typename T>