Solved

stack class using a templace vector class overloading [] problem

Posted on 2014-09-28
5
254 Views
Last Modified: 2014-09-29
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;
0
Comment
Question by:pcomb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 40348838
Could you post the complete code? These snippets alone aren't really insightful...
0
 

Author Comment

by:pcomb
ID: 40348846
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40348891
Ah, I think I got it - you had your accessors all in the form 'Base<T> operator[](int index);' where you need them to be like 'T operator[](int index);'. Try the following (also check for '<--' which I used to mark other issues):
base.h
pile.h
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40348990
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.
0
 

Author Closing Comment

by:pcomb
ID: 40349000
perfect many thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to programmatically differentiate between C and Java 10 222
Least Squares Curve Fitting 4 134
Which Linux flavors will this run on? 6 116
using interface in TLB 3 32
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question