自动将父指针传递给其变量
Automatically Pass Parent Pointer to its Variables?
这是我目前拥有的功能,我想知道是否有一种方法可以将父指针传递到它的所有变量,而不需要所有的= this
?
struct Location;
struct Parent
{
std::vector<Location*> locations;
};
struct Location
{
Location(Parent* p)
{
p->locations.push_back(this);
}
};
struct SpecialParent : Parent
{
Location a = this;
Location b = this;
Location c = this;
Location zabaZoo = this;
// etc
};
这样做的目的是,我仍然可以进行specialParent->zabaZoo
,但仍然可以批量处理某些操作的位置。
Location a = b = c = zabaZoo = this;
敏捷的棕色狐狸跳过懒狗。
您可以创建一个SpecialParent
构造函数,并使用赋值:
Location a, b, c, zabaZoo;
SpecialParent()
{
a = b = c = zabaZoo = Location(this);
}
相关文章:
- 将地址分配给本地指针后,公共对象的变量将消失
- 如果非动态变量被指针引用,何时超出范围?
- 在函数结束后使用指向变量的指针是否安全?
- 有没有将变量名称转换为双指针的简短方法?
- 成员变量指针的函数参数包
- C++ - 使用变量指针调用函数
- 如何返回值为NULL的变量指针
- 在编译时以增量方式构建变量指针的向量
- C 取消实例变量指针
- 每个方法调用上都覆盖了本地变量指针
- 决定对基类的变量指针进行函数调用
- 使用 valgrind 时获得 int 变量指针的无效读取大小错误
- 变量指针的成员函数未绘制到SDL_Surface?
- 何时使用成员变量指针
- 从成员变量指针返回布尔值
- 指向C#和C++之间接口的变量指针
- c++中指向self的成员变量指针
- 为什么变量指针包含相同数据类型的地址?
- 指向用户定义类型的类的全局变量指针
- C++分配一个变量指针地址