473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

std::list problems

Hello,

I'm writing a connection management class, but I'm running into
problems with the std::list template. I want to use a list to help
manage my Connection objects.

The ConnectionManager header file has the following inside the class
definition:

private:
typedef std::list<Connection *> ConnectionList;
typedef std::list<Connection *>::const_iterator const_iterator;
ConnectionList connections;

I've got the following method inside my ConnectionManager class.

void ConnectionManager::add(Connection *c)
{
connections.push_back(c);
}

When I call that method using the following snippet of code:

cm->add(new Connection(fd));

I get a segmentation fault. I've ran gdb on the core file and a
backtrace looks like this:

(gdb) backtrace
#0 0xb7f0a52c in std::_List_node_base::hook () from
/usr/lib/libstdc++.so.6
#1 0x0804def9 in std::list<Connection*, std::allocator<Connection*>
::_M_insert (this=0xb7f8d008, __position={_M_node = 0xb7f8d008}, __x=@0xbfcb9374) at stl_list.h:1153
#2 0x0804df36 in std::list<Connection*, std::allocator<Connection*>::push_back (this=0xb7f8d008, __x=@0xbfcb9374) at stl_list.h:774

#3 0x0804db39 in ConnectionManager::add (this=0xb7f8d004, c=0x806f098)
at connectionmanager.cpp:19
#4 0x0804c6ec in SocketManager::processReady (this=0xbfcb957c,
s=@0xbfcb93f0)
at socketmanager.cpp:52
#5 0x08049866 in main (argc=1, argv=0xbfcb9634) at enraged.cpp:37
(gdb)

I'm rather new to C++ (and gdb), so I'm a bit confused as to why this
is failing.

Can anybody guide me in the right direction?

Regards,

Sidaf

Jun 25 '06 #1
2 6004

"sidaf" <si*********@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hello,

I'm writing a connection management class, but I'm running into
problems with the std::list template. I want to use a list to help
manage my Connection objects.

The ConnectionManager header file has the following inside the class
definition:

private:
typedef std::list<Connection *> ConnectionList;
typedef std::list<Connection *>::const_iterator const_iterator;
ConnectionList connections;

I've got the following method inside my ConnectionManager class.

void ConnectionManager::add(Connection *c)
{
connections.push_back(c);
}

When I call that method using the following snippet of code:

cm->add(new Connection(fd));

I get a segmentation fault. I've ran gdb on the core file and a
backtrace looks like this:

(gdb) backtrace
#0 0xb7f0a52c in std::_List_node_base::hook () from
/usr/lib/libstdc++.so.6
#1 0x0804def9 in std::list<Connection*, std::allocator<Connection*>
::_M_insert (this=0xb7f8d008, __position={_M_node = 0xb7f8d008},
__x=@0xbfcb9374)

at stl_list.h:1153
#2 0x0804df36 in std::list<Connection*, std::allocator<Connection*>
::push_back (this=0xb7f8d008, __x=@0xbfcb9374) at stl_list.h:774

#3 0x0804db39 in ConnectionManager::add (this=0xb7f8d004, c=0x806f098)
at connectionmanager.cpp:19
#4 0x0804c6ec in SocketManager::processReady (this=0xbfcb957c,
s=@0xbfcb93f0)
at socketmanager.cpp:52
#5 0x08049866 in main (argc=1, argv=0xbfcb9634) at enraged.cpp:37
(gdb)

I'm rather new to C++ (and gdb), so I'm a bit confused as to why this
is failing.

Can anybody guide me in the right direction?

Regards,

Sidaf


this code looks totally correct.
Something must be wrong with the state of your program before this has been
executed.
Use valdgrind to find such kind of bugs on INTEL LINUX.
Use purify on other systems

Jun 26 '06 #2
sidaf wrote:
I'm writing a connection management class, but I'm running into
problems with the std::list template. I want to use a list to help
manage my Connection objects.

The ConnectionManager header file has the following inside the class
definition:

private:
typedef std::list<Connection *> ConnectionList;
typedef std::list<Connection *>::const_iterator const_iterator;
ConnectionList connections;
Seems fine to me.
I've got the following method inside my ConnectionManager class.

void ConnectionManager::add(Connection *c)
{
connections.push_back(c);
}
No problem here AFAICS.
When I call that method using the following snippet of code:

cm->add(new Connection(fd));
What's "cm"? How is it allocated?
I get a segmentation fault.
What's "Connection" how does it get created with an argument?
I've ran gdb on the core file and a
backtrace looks like this:

[...]
That's irrelevant in comp.lang.c++. C++ does not define 'backtrace'.
I'm rather new to C++ (and gdb),
'gdb' is not part of C++. If you need help with 'gdb', you need to
find a better place than c.l.c++. Try 'gnu.utils.help' or try some
online (web) GNU forums.
so I'm a bit confused as to why this
is failing.

Can anybody guide me in the right direction?


This is convered in FAQ 5.8. Please read the FAQ before posting.
You can find FAQ Lite here: http://www.parashift.com/c++-faq-lite/

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Magnusson | last post by:
I know a similar question was recently posted here, but after trying the solutions in that thread I still have problems. list<int> the_list; the_list.push_back(1); the_list.push_back(2);...
14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
8
by: ma740988 | last post by:
Consider: # include <iostream> using std::cout; using std::cin; using std::endl; # include <list> using std::list;
7
by: Gernot Frisch | last post by:
class A { public: std::list<A> m_a; }; yields errorC2079: '_Value' uses undefined class 'A' using std::vector will work...
5
by: gerg | last post by:
I'm having to deal with some legacy code which I think may be causeing some problems. Can STL pro's please add comments about the correctness of the following code: class A { public: /// ......
4
by: Jim Langston | last post by:
Expected output is: Three One One Actual output is: Three One Two
2
by: ranin02 | last post by:
Hi, We have a list derived from std::list that has a custom allocator derived from std::allocator. This was originally written using VC++ 6.0 which required a workaround for the fact that 6.0...
7
by: TBass | last post by:
So I have a class: class Client { unsigned int ClientID; .... }; class MyListenSocket
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.