我有一个关于“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 );
}
};
以这种方式使用“this”通常是不好的做法吗?
感谢您的帮助。
最佳答案
不,只要您在所有权和删除方面小心谨慎,这没有任何问题。
关于c++ - 这个指针的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3096617/