Mew*_*zer 4 c++ stl class this
我有一个关于"this"用法的问题.
假设我有两个A和B类; 他们的粗略轮廓如下:
class A
{
public:
...
void AddB( B* b )
{
// inserts B into the vector v
}
private:
std::vector<B*> v;
};
class B
{
public:
...
void foo( void )
{
...
// Adds itself to the queue held in A
a.AddB( this );
}
};
Run Code Online (Sandbox Code Playgroud)
使用"这个"这种方式一般是不好的做法?
谢谢您的帮助.
不,这没有什么不妥,只要你小心所有权和删除.
| 归档时间: |
|
| 查看次数: |
207 次 |
| 最近记录: |