c++ - Is passing a pointer by reference the correct way to do this? -


this function:

void createrendertarget(hwnd, id2d1hwndrendertarget*); 

and there how works:

void d2dres::createrendertarget(hwnd hwnd, id2d1hwndrendertarget* prt) {     rect rc;     getclientrect(hwnd,&rc);      pfactory->createhwndrendertarget(             d2d1::rendertargetproperties(),             d2d1::hwndrendertargetproperties(                 hwnd,                 d2d1::sizeu(                     rc.right - rc.left,                     rc.bottom - rc.top)),                 &prt); } 

it called this:

pd2dres->createrendertarget(map.gethwnd(),map.getprt()); 

once returning createrendertarget(), map.prt null. how comes?

edit: there getprt() function:

id2d1hwndrendertarget* mapeditor::getprt() {     return prt; } 

first problem:

once returning createrendertarget(), map.prt null. how comes?

because not passing pointer by reference. in order pass reference, signature of createrendertarget() should be:

void createrendertarget(hwnd, id2d1hwndrendertarget*&); //                                                  ^ 

unless that, createrendertarget() working on copy of pointer passed argument, , changes value won't affect original pointer.

second problem:

you write:

[...] there getprt() function:

id2d1hwndrendertarget* mapeditor::getprt() {     return prt; } 

notice, getprt should return reference internal prt pointer, otherwise above change won't have effect (you passing reference copy of original prt.

therefore, should modify signature accordingly:

id2d1hwndrendertarget*& mapeditor::getprt() //                    ^ {     return prt; } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -