Link to home
Start Free TrialLog in
Avatar of pcomb
pcombFlag for United States of America

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;
Avatar of jkr
jkr
Flag of Germany image

Could you post the complete code? These snippets alone aren't really insightful...
Avatar of pcomb

ASKER

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoffric
phoffric

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.
Avatar of pcomb

ASKER

perfect many thanks