By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,795 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,795 IT Pros & Developers. It's quick & easy.

How Hazardous is the following code

P: n/a
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

}
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Barry Hynes" <hy****@mar.dfo-mpo.gc.ca> skrev i en meddelelse
news:zk*******************@ursa-nb00s0.nbnet.nb.ca...
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
Jul 23 '05 #2

P: n/a

"Peter Koch Larsen" <pk*****@mailme.dk> wrote in message
news:iy*********************@news000.worldonline.d k...

"Barry Hynes" <hy****@mar.dfo-mpo.gc.ca> skrev i en meddelelse
news:zk*******************@ursa-nb00s0.nbnet.nb.ca...
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?
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
/Peter

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.