pcomb
asked on
stack class using a templace vector class overloading [] problem
I have built a vector template class and I am now building a stack class that uses the vector class.
When I overload the [] operator I am getting a cannot convert int to vector <T> c2440
definiton of {} are
Vector<T> & operator[](int index);
const Vector<T> & operator[](int index) const;
func is
template<typename T>Vector<T> & Vector<T>::operator[](int index) // Returns an object at location index without bounds checking
{
return vec_array[index];
}
template<typename T>const Vector<T> & Vector<T>::operator[](int index) const // Returns an object at location index without bounds checking
{
return vec_array[index];
}
Stack is
template <class T>
class stack: Vector <T>
{
private:
Vector<T> stack_array;
instantiated using
stack<int> Stack1;
When I overload the [] operator I am getting a cannot convert int to vector <T> c2440
definiton of {} are
Vector<T> & operator[](int index);
const Vector<T> & operator[](int index) const;
func is
template<typename T>Vector<T> & Vector<T>::operator[](int index) // Returns an object at location index without bounds checking
{
return vec_array[index];
}
template<typename T>const Vector<T> & Vector<T>::operator[](int index) const // Returns an object at location index without bounds checking
{
return vec_array[index];
}
Stack is
template <class T>
class stack: Vector <T>
{
private:
Vector<T> stack_array;
instantiated using
stack<int> Stack1;
Could you post the complete code? These snippets alone aren't really insightful...
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I noticed the T vs. Base<T> issue. But then I figured that the author must have tested his base class thoroughly before trying to use it, and concluded that I must have skimmed over the base class too fast.
Could you post your Base class tests (i.e., the test.cpp file that thoroughly verifies your base class.
In general, when you use a user defined type, the assumption is that this UDT has been tested.
Could you post your Base class tests (i.e., the test.cpp file that thoroughly verifies your base class.
In general, when you use a user defined type, the assumption is that this UDT has been tested.
ASKER
perfect many thanks