开发者

How to modify a function behaviour without template method?

I have a function (actually from ATL, it is ATL::CSoapMSXMLInetClient::SendRequest(LP开发者_C百科CTSTR)) whose behaviour should slightly be modified. That is, I just have to add one function call somewhere in the middle of the function.

Taking into consideration that this is not a template method, what is the best practice of changing its behaviour? Do I have to re-write the whole function?

Thanks in advance.

EDIT: Deriving from the class ATL::CSoapMSXMLInetClient and copy-pasting whole function code with a slight modification in subclass function definition does not work because most of the members used in ATL::CSoapMSXMLInetClient::SendRequest are "private" and accessing them in subclass is a compile time error.

Rather than best practice I am looking for a way to do it now, if there is any. :(


Yes you will. If it's in the middle of the function there is no way of getting around it.


There are some refactoring methods you can use. But I cannot think of any pretty ones, and all depend heavily on the code within the class, although for you case it might be tough to find any that works.

Like if you have a line:

do_frobnicate();
dingbat->pling();

And you need to call somefunc() after the dingbat plings. You can, if the dingbat is an interface that you provide, make a new dingbat that also do somefunc() when it plings. Given that the only place this dingbat plings is in this function.

Also, if do_frobnicate() is a free function and you want to add the somefunc() after this, you could create a function within the class, or within its namespace that is called the same. That way you make your own do_frobnicate() that also does somefunc().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜