| re: How Hazardous is the following code
"Barry Hynes" <hynesb@mar.dfo-mpo.gc.ca> skrev i en meddelelse
news:zkwQd.2833$oh4.109269@ursa-nb00s0.nbnet.nb.ca...[color=blue]
> Hi Folks,
>
> still on the linked list problem...
>
> how hazardous is the following code...i realize i do not have
> copy/assignment defined and there is no exception handling...but was
> wondering about the stl::list constructor and destructor.
>
> i cannot inherit stl::list's ctor or dto - i think. Do not know how to
> properly create/breakdown base class
>
> any help greatly appreciated
>
> Barry
>
> // safeList.h
>
> #ifndef SAFELIST_H
> #define SAFELIST_H
>
> using namespace std;
> #include <list>
> #include <iterator>
> #include <memory>
> #include <stdexcept>
>
> //typedef list<T> S;
> //typedef list<T>::iterator SI;
>
> template<typename T>
> class SafeList : private list<T> {
> public:
> SafeList() : list<T>() {}//No no-arg ctor not sure if i correctly
> created an stl::list?
> using list<T>::push_front;
> using list<T>::size;
> virtual ~SafeList() {}[/color]
No reason for a virtual destructor here. SafeList is NOT a list.
[color=blue]
> private:
> // SafeList(const SafeList&);
> // SafeList& operator = (const SafeList&);
> };
> #endif
>
> #include <iostream>
> #include "safeList.h"
>
> using namespace std;
>
> int main()
> {
> SafeList<int> SL;
> SL.push_front(10);
> SL.push_front(20);
> SL.push_front(30);
> SL.push_front(40);
> cout << "The size of the list is: " << SL.size() << endl;
> //i think i should call ~stl::list<T>...not sure
>
> }
>
>[/color]
I see no problem but also I do not see what you solve. A list with only some
of the "goodies" available?
/Peter |