Sternoceral

Hello,

I'm having some syntax difficulties. I want to set a pointer to point to a variable like this (CTREEITEM is HTREEITEM* , and GetSelectedItem() returns a HTREEITEM) :

Code Snippet

CTREEITEM = &pCtrl->GetSelectedItem();


In the past, I've done something similar:

Code Snippet

pCtrl = &this->GetTreeCtrl();


That worked as expected, but now I'm getting the compile-time error message "C2102: '&' requires l-value".

I'm at a loss as to what to do. Please advise.


Re: Visual C++ Language Obtaining a memory address of a variable returned by a class member function

Viorel.

I think you do not need pointers here. You can use HTREEITEM directly. For example:

HTREEITEM selected_item = pCtrl->GetSelectedItem();

(The error is caused by the fact that the return value is in a temporary location (register) which cannot be addressed by pointers. Compare with this error: int * p = &strlen("abc"); )

I hope this makes sense.





Re: Visual C++ Language Obtaining a memory address of a variable returned by a class member function

Sanket_Shah_734609

Can you explain a little bit more





Re: Visual C++ Language Obtaining a memory address of a variable returned by a class member function

Sternoceral

I'm using a HTREEITEM* to store the current HTEEITEM.

I tried using an actual HTREEITEM to store the current HTREEITEM. It works nicely. I'll go with this.

Thanks