Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

面向切面编程中织入类成员函数并带参数 #30

Open
StartingnewDJW opened this issue Apr 12, 2019 · 5 comments
Open

面向切面编程中织入类成员函数并带参数 #30

StartingnewDJW opened this issue Apr 12, 2019 · 5 comments

Comments

@StartingnewDJW
Copy link

问一下版主 Aspect.hpp
怎么织入类函数成员,带参数变量(切面函数before,after同样传入参数?)

@qicosmos
Copy link
Owner

你看一下feather是怎么织入切面的:
https://github.com/qicosmos/feather/blob/master/main.cpp#L64

@StartingnewDJW
Copy link
Author

自己实验,只能在织入的类函数传入参数,而切面函数无法获取这些参数。
InferCaffeNetwork fcn;
int gpu_id=1;
cout<<"class method"<<endl;
Invoke

([&fcn,gpu_id]{fcn.SetNetWorkGPU(gpu_id);});

@qicosmos
Copy link
Owner

@StartingnewDJW
Copy link
Author

StartingnewDJW commented Apr 13, 2019

问一下可不可以实现动态的注册一个模板类?大概想法是:现在存在一个类Obj obj1、一个类模板(即观察者模式里的Events模板),想要在obj实例调用一个函数实现对特定形式的events类的添加
obj1.function(Func){
Events < Func > it;
obj1.vec1.push_back(it);
}

@qicosmos
Copy link
Owner

没看懂你的问题。切面的参数和业务函数的参数是相同的,如果你想设置额外的参数,你可以在切面类里面加,然后再切面函数里自己去处理,这是灵活的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants