Click here to Skip to main content
15,891,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I traced C++ codes from others; containing a statement
std::istream response_stream(&*response_);
where response_ is defined as
boost::asio::streambuf * response_;

Does it make sense to user & and * before response_ like
&*response_
?

Isn't "&*response_" equal to just 'response_'?
Posted

1 solution

You did not add much code to clarify, but as it is written it looks like a function declaration - in that case it makes sense.

Defining a parameter as & in a c++ function declaration means that the parameter is passed by reference, as in the next example

C++
void same(int &n);  // declaration of the prototype with a reference
int main(){
    int iA = 5;   // Define a number
    same(iA);     // pass the variable to ur function BY REFERENCE
    cout << iA; // Without the reference passing I should see 5; By reference I can 
                // change the value of the parameter, so now iA equals 6;
    return 0; // Exit from main
}
void same(int &n){
    n = 6;
}


So by passing a parameter as &*response_ I'm passing a reference to the object pointed by response_.

I hope I have been clear enough (English is not my primary language) and to have helped you.

EDIT: I found an article on CodeProject Pointer to Pointer and Reference to Pointer[^], maybe it helps you.

- Denis
 
Share this answer
 
v2
Comments
Stan Huang 22-Mar-15 23:52pm    
I accept it. BTW, what does "void func(ClassA^% thObj);" mean in below function from the article you mentioned ( Pointer to Pointer and Reference to Pointer[^])?

//function prototype
void func(ClassA^% thObj);

int main()
{
ClassA^ obj = gcnew ClassA;
ClassA^ obj2=&obj;
func(obj2);
....
return 0;
}
den2k88 23-Mar-15 3:56am    
Oh, sorry, I didn't look deeply in the article: it means the same as *& but in a C++/CLI (for .NET) context.

^ means the same as * but for a managed reference, while ^% means the same as *&. More on wikipedia: http://en.wikipedia.org/wiki/C%2B%2B/CLI
and MSDN of couse explains better (I have only a little experience with .NET).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900