S
sidaf
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
at connectionmanager.cpp:19
#4 0x0804c6ec in SocketManager:rocessReady (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
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
at stl_list.h:1153#1 0x0804def9 in std::list said:::_M_insert (this=0xb7f8d008, __position={_M_node = 0xb7f8d008}, __x=@0xbfcb9374)
#3 0x0804db39 in ConnectionManager::add (this=0xb7f8d004, c=0x806f098)#2 0x0804df36 in std::list said::ush_back (this=0xb7f8d008, __x=@0xbfcb9374) at stl_list.h:774
at connectionmanager.cpp:19
#4 0x0804c6ec in SocketManager:rocessReady (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