Re: [C++] Templates and inheritance

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 09/28/04


Date: Tue, 28 Sep 2004 22:58:59 +0100

In article <slrncljmco.usv.hexkid@ID-203069.user.uni-berlin.de>, Pedro
Graca <hexkid@hotpop.com> wrote:

> Alwyn wrote:
> > In article <slrncliuer.usv.hexkid@ID-203069.user.uni-berlin.de>, Pedro
> > Graca <hexkid@hotpop.com> wrote:
>
> ========
> I'm now trying to make a
>
> InheritedStack<foo> bar; // :-)
>
> where foo is a class of my own ...
>
> I'm getting a lot of errors, especially with
> operator overloading (for > and <<), but I will
> wait a week or so for my books before showing
> my newbieness :-)

On the whole, it is not a good idea to inherit from STL classes. They
are not designed for that. I would rather write:

template <class T>
class Stack
{
   std::stack<T> theStack;
public:
   bool empty() const {
      return theStack.empty();
   }
   size_t size() const {
      return theStack.size();
   }
   void push(const T &);
   // etc etc.
};

although it is a pain, I admit.

As far as the operators '<' and '<<' are concerned, have you defined
them for your class? You may need to do this.

Alwyn



Relevant Pages

  • Re: Funky function
    ... >> It makes it possible to call this member function on a const object ... >> object may or may not be const). ... int Data; ... in the next line you try to call a function foo on MyData. ...
    (comp.lang.cpp)
  • Inheritance and object factories...HELP!!
    ... Now foois a const member function so the way it has to work is to ... The member function foo creates a new object on the stack and returns it ... The foooperation is identical for deriv1 and deriv2 except that it ...
    (comp.lang.cpp)
  • Re: compile error about auto_ptr
    ... The signature of `vector::push_back' method requires const ... void push_back (const Foo& input) ...
    (microsoft.public.vc.language)
  • Re: Overloading funtions with const qualifier
    ... > So what would happen if I would call foo on references? ... member functions (which implicitly take const or non-const references to the ... overload non-member functions in this way (although that doesn't mean there ...
    (comp.lang.cpp)
  • RE: function overloading, parameter list error
    ... However, the const in "Type foo(int x, int y) const" only indicates that ... foo does not change it's object memory. ... method you are calling the assignment? ...
    (microsoft.public.vc.language)