Re: Best way to "redefine" a std class

From: adbarnet (adbarnet_at_barnet.com)
Date: 12/07/04


Date: Tue, 7 Dec 2004 20:24:59 -0000


..as for the iterators - just typedef them:

template <typename T> myList {
public:
   typedef std::list<T> MyListType;
    MyListType::const_iterator const_iterator;

    const_iterator begin() const { return theList.begin(); }
    const_iterator end() const { return theList.end(); }

private:
    MyListType theList;
    MyListType::iterator iterator;
    iterator begin(){ return theList.begin(); }
    iterator end() { return theList.end(); }
};

"Nafai" <nafai3000@yahoo.es> wrote in message
news:Mogtd.4193329$A6.12929524@telenews.teleline.es...
> Hello I want to define a class myList, which is the same that std::list
> except from:
> - insert (I want to redefine it)
> - elements can only be consulted or deleted but not modified.
> - I want
>
> Which is the best way to do that?:
>
> 1.
> template <typename T> myList : public list<T> {
> public:
> insert(...) { ... }
> ...
> // what about iterators?
> };
>
> OR
>
> 2.
>
> template <typename T> myList {
> private:
> list<T> theList;
> public:
> // all the methos of list addapted to myList
> // i.e.:
> int size() {return theList.size(); }
> ...
> // what about iterators?
> };
>
>
>
>
>



Relevant Pages

  • Template member function cast bug in VC80SP1 (and more...)
    ... writing a small piece of metaprogramming code, we had to face some problems: ... and both MAP_BASE and MAP define 'iterator' as ... we'll omit template parameters from the text, ... template <typename S> ...
    (microsoft.public.vc.language)
  • Re: problems with friend class in templates
    ... > private data members of another class, ... I can't get the friend class to work. ... > template ... the map class and the iterator class are friends of each other. ...
    (microsoft.public.dotnet.languages.vc)
  • traits help
    ... I am learning template programming and there is a problem about ... Now consider a container and an iterator. ... template <typename T> ...
    (comp.lang.cpp)
  • Re: how to use recursive algorithm to determine all of the arrangements?
    ... class IndexMapper implements Iterator { ... private Object map; ... public PossibleSets(int from, int choose) { ... primedWithAValue) ...
    (comp.lang.java.programmer)
  • Re: iterator over superclass of collection
    ... extends Aye> iterator() { ... Iterable that returns elements which are assignment-compatible with Aye. ... It’s not because it extends a wildcard capture that people will suddenly ... private class PrivateAye extends A implements Aye { ...
    (comp.lang.java.programmer)