I have some code which use ‘this’ pointer of class which calls this code. For example:
Some::staticFunction<templateType>(bind(FuncPointer, this, _1));
Here is I’m calling bind function from boost. But it doesn’t matter. Now I have to wrap this code. I made a macro:
#define DO(Type, Func) Some::staticFunction<Type>(bind(FuncPointer, this, _1));
And compiler insert this code into class which calls this macro, so ‘this’ takes from caller. But I don’t want to use macro and prefer function (inline). But how to resolve ‘this’ passing. Could I use it in inline function like in macro or I have to pass it manually?
The
thiskeyword can be put by the function you callAfter which you can call
If you like you can inherit the function
That way you can just use
doitand not first write it, just like with the macro. Useful if you have a wide range of classes that you use the function in.Edit: Notice that the C-Style cast is required here (can’t use
static_cast), because of the private inheritance. It’s a safe cast ifTis derived fromMyRegister<T>Personally i would prefer this over the macro. Notice that your macro can’t cope with commas in the type-name
This tries to pass 3 arguments to the macro instead of 2. You could reverse the order of the type and the function and use variadic macros (which are a C++0x feature, but available in some compiler in C++03 mode) or you could use a typedef and pass the alias name.