c++ - Segmentation fault using FastDelegate -



c++ - Segmentation fault using FastDelegate -

i've got problem test code. compiles well, when seek phone call delegate, programme crashes.

#include "..\libs\fastdelegate\fastdelegate.h" #include <string> #include <map> #include <iostream> typedef fastdelegate::fastdelegate1 <int, int> funcptr; struct function { funcptr ptr; int param; function() {}; function (funcptr ptr_, int param_): ptr (ptr_), param (param_) {}; int operator() (int xxx) {return ptr(xxx);}; }; std::map <std::string, function> externalfuncs; bool registerfunction (const std::string& a, const function b) { externalfuncs[a] = b; homecoming true; } int foo (int bar) { std::cout << "jest gites"; homecoming 0; } int main() { registerfunction ("foo", function(&foo, 1)); externalfuncs ["foo"] (5); }

callstack:

#0 00000000 0x00000000 in ??() (??:??) #1 0041f209 fastdelegate::fastdelegate1<int, int>::operator() (this=0x3e256c, p1=5) (f:/projekty/aaa/../libs/fastdelegate/fastdelegate.h:991) #2 0041d774 function::operator() (this=0x3e256c, xxx=5) (f:\projekty\aaa\main.cpp:14) #3 00401526 main() (f:\projekty\aaa\main.cpp:34)

registerfunction ("foo", function(&foo, 1)); ^ capital f externalfuncs ["foo"] (5); ^ lowercase f

since there no element in map key "foo", externalfuncs["foo"] default constructs new function, inserts default constructed object map, , returns reference it; phone call operator() on object, attempts dereference uninitialized ptr fellow member variable. bad things happen.

c++ stl delegates crash segmentation-fault

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -