Wednesday, June 7. 2006Callbacks and derived classes in C++Comments
Display comments as
(Linear | Threaded)
warning - Unhelpful comment... Anyway, it's some time ago since I did C++ but why do you do the
do { ... } while(0) in the macro? If you want to create a new scope for the statements simply { ... } should do the job (or I'm confusing this with Java). Sorry that I can't help you with the template problem and thanks for reminding me how great it is that I can use Java in my current projects
That's the proper way of implementing a multistatement macro in C/C++. The comp.lang.c FAQ has more details about it: http://c-faq.com/cpp/multistmt.html
Thanks, I didn't know that. I just looked it up in the C++ grammar [1], and C++ should recognize "{};". Also,
the following program compiles without error or warning with g++: int main(int argc, char **argv) { {}; return 0; } [1] "Die C++ Programmiersprache" (The C++ Programming Language), Bjarne Stroustrup, Appendix A
Sorry, my fault. Of course my example is illegal. And I looked up the wrong definitions in the grammar - I am a bad compiler - so you're right. Best way to to mulit-statement macros.
template <typename T>
class context { void register_action(string, callback<T> * ); map<string, callback<T> *> actions; }; class derived : public context<derived> { }; so gehts auch ohne casten, weil eine methode in context auch als (derived::*)() gefunden wird. das pattern mit dem public context<derived> heisst "curiously recurring template pattern". selbst in der context klasse kann man T::*method schreiben, um auf eine methode der context-klasse zu pointen, weil die methoden von context an T (oder derived in diesem fall) vererbt werden. uebrigens ist callback::callee wharscheinlich immer identisch mit this in context::dispatch_action, oder? eine heapallokation solltest du auch vermeiden und eine map<string, callback<T> > verwenden |
Calendar
QuicksearchShow tagged entries22c3 23c3 amsterdam announcement apache argentina army austria beer berlin blog book borland bsd c c++ callofduty2 camera censorship chernobyl cms complaint concert cooking electronic music email fail feedreader fefe food fun gas mask gcc german germany git gnu golang google hacking history html http hudson i18n imap internet israel javascript job kaminer lecture linux linz mobile movie music network newsbeuter noos panorama pearl jam performance photo photography photos pictures polaroid police politics problem programming quiz rant recommendation release rss ruby screencast seagull security series server ska skabucks stfl terrorism travelling tv unix usa video vienna war weird wikipedia windows work wplotd youtube
Blog AdministrationLinksBlogroll• xkcd.com
• Planet Debian • MY POV ([expect the unexpected]) • C skills • Planet Erlang / Published News • armstrong on software • Photos from akrennmair • Das Metalab informiert • dive into mark • /usr/local/bin • F!XMBR • heise online News (full feed) • JLog • SecuriTeam Blogs • .:Computer Defense:. • Riot Porn • Chaosradio • Radiomultikulti vom RBB: Russendisko unplugged • AK's weblog • The Recurity Lablog • milw0rm.com • seclog.de • ilja's blag • udo.kernecker.at - mein leben als prinzregent... ;-) • grabnerandi.at diary feed • Hilli's WebLog • accidents waiting to happen • Venzi's Weblog • TaoSecurity • Irrlicht3d.org • murphee's Rant • waiterrant.net • grml development blog • mutt Changelog • nion's blog • Wannabe Everything • blog@bytelabs • Knowledge Brings Fear • Die wunderbare Welt von Isotopp • Fefes Blog • law blog • mikas blog • BILDblog • GoogleWatchBlog • Krone - Blog • The Lunatic Fringe • mp's blog • Su-Shee 2.0 • Sex, Drugs & Compiler Construction • Qbi's Weblog • gedankensplitter • Ohns Gehirnschleimschmiede • fh • Clifford Wolf's Blog • AK's moblog • Telepolis News • Slashdot • Newssystem von bundesheer.at • Riding Rails - home • Serendipity • O'Reilly Ruby • CCC Events Weblog • del.icio.us/dubrider • del.icio.us/timpritlove • del.icio.us/ak • del.icio.us/mika • AK's Soup • Friends of ak • Astronomy Picture of the Day • german-bash.org - Die neuesten Zitate • QDB • WeirdWeirdWorld Latest Feed • I CAN HAS CHEEZBURGER? • The Trailer Mash • Cruel.Com • fun.drno.de • Peter Pilz grüner Sicherheitssprecher Österreich Wien • NPD-BLOG.INFO • INSM Watchblog • Hitler-Blog • Everybody loves Eric Raymond • Dilbert |
In the last few days, I was working hard to finish a first working version of my "cwapd" (totally uninspired name, I know, it's supposed to mean "C++ Web Application Platform Daemon"). It is based on my previously-mentioned HTTP stack. The basic concep
Tracked: Jun 09, 20:22