0

ダブルポインタを使用する必要があるコードがいくつかあります。具体的には、なぜ私がどこで言うことができない&thisのかについて興味があります...

class Obj {
public:
    void bar();
};

void foo(Obj **foopa)
{
    // do etc with your foopa.  maybe lose the foopa altogether. its nasty imo.
}

void Obj::bar()
{
    // call foo(Obj **)
    foo(&this);  // Compiler Err:  Address extension must be an lvalue or a function designator.
}

左辺値?機能指定子?返信が大好きです。

4

1 に答える 1

1

「this」は特別なポインターであり、変更することは想定されていませんが、「Obj *t」を関数に入れないでください。関数の最後で破棄されるため、そうする必要があります。静的。

class Obj;
Obj *t;

class Obj {
public:
    void bar();
};

void foo(Obj **foopa)
{
    // do etc with your foopa.  maybe lose the foopa altogether. its nasty imo.
}

void Obj::bar()
{
    // call foo(Obj **)
    t = this;
    foo(&t);  // Compiler Err:  Address extension must be an lvalue or a function designator.
}
于 2012-12-06T09:02:20.380 に答える