How Hazardous is the following code

B

Barry Hynes

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

}
 
P

Peter Koch Larsen

Barry Hynes said:
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() {}

No reason for a virtual destructor here. SafeList is NOT a list.
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

}
I see no problem but also I do not see what you solve. A list with only some
of the "goodies" available?

/Peter
 
B

Barry Hynes

Peter Koch Larsen said:
No reason for a virtual destructor here. SafeList is NOT a list.

I see no problem but also I do not see what you solve. A list with only some
of the "goodies" available?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top