【发布时间】:2012-10-05 17:12:09
【问题描述】:
是否可以使用 -- 或 ++ 运算符更改我当前结构的地址,即:
mystruct* test = existing_mystruct;
test++ // instead of using: test = test->next_p;
我试图使用它,但它似乎是 const 并给了我一个错误:分配给这个(不合时宜):
struct mystruct {
mystruct* next_p;
mystruct* prev_p;
void operatorplusplus () { this = next_p; }
void operatorminusminus() { this = prev_p; }
};
【问题讨论】:
-
this = (anything)极不可能在标准编译器中工作。 IIRCthis被认为是 const。 -
@cHao: IIRC
this是一个右值表达式,比const更难赋值。 -
历史记录:
this曾经是可修改的,早在早期;在构造函数中分配给this类似于今天的放置 new。 -
@PeteBecker 所以你会失去你曾经占用的内存?
-
@SethCarnegie - 我已经告诉了你我所知道的一切。
标签: c++ struct operator-keyword