469,578 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

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 5798

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Martin Magnusson | last post: by
14 posts views Thread by Dave | last post: by
8 posts views Thread by ma740988 | last post: by
7 posts views Thread by Gernot Frisch | last post: by
5 posts views Thread by gerg | last post: by
4 posts views Thread by Jim Langston | last post: by
2 posts views Thread by ranin02 | last post: by
7 posts views Thread by TBass | last post: by
11 posts views Thread by Juha Nieminen | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.