Convert "this" to a reference-to-pointer

Posted by Austin Hyde on Stack Overflow See other posts from Stack Overflow or by Austin Hyde
Published on 2010-04-28T00:47:21Z Indexed on 2010/04/28 0:53 UTC
Read the original article Hit count: 443

Filed under:
|
|

Just stumbled onto this problem. (title says it all)

Let's say I have a struct

struct Foo {
    void bar () {
       do_baz(this);
    }
    void do_baz(Foo*& pFoo) {
       pFoo->p_sub_foo = new Foo; // for example
    }
    Foo* p_sub_foo;
}

GCC tells me that

temp.cpp: In member function ‘void Foo::bar()’:
temp.cpp:3: error: no matching function for call to ‘Foo::do_baz(Foo* const)’
temp.cpp:5: note: candidates are: void Foo::do_baz(Foo*&)

So, how do I convert what is apparently a const Foo* to a Foo*&?

© Stack Overflow or respective owner

Related posts about c++

Related posts about pointers