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

std::list problems

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

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