Connecting Tech Pros Worldwide Forums | Help | Site Map

How Hazardous is the following code

Barry Hynes
Guest
 
Posts: n/a
#1: Jul 23 '05
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() {}
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

}



Peter Koch Larsen
Guest
 
Posts: n/a
#2: Jul 23 '05

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


Barry Hynes
Guest
 
Posts: n/a
#3: Jul 23 '05

re: How Hazardous is the following code



"Peter Koch Larsen" <pklspam@mailme.dk> wrote in message
news:iywQd.100320$Vf.3897149@news000.worldonline.d k...[color=blue]
>
> "Barry Hynes" <hynesb@mar.dfo-mpo.gc.ca> skrev i en meddelelse
> news:zkwQd.2833$oh4.109269@ursa-nb00s0.nbnet.nb.ca...[color=green]
> > 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=green]
> > 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[/color]
some[color=blue]
> of the "goodies" available?[/color]

i am in the process of populating it with some goodies...slowly :)
but i was wondering if i actually got an stl::list up and running and didn't
send my PC in la la land when stl:list went out of scope

thanks for the help

Barry[color=blue]
>
> /Peter
>
>[/color]


Closed Thread