Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 570 Bytes

File metadata and controls

34 lines (24 loc) · 570 Bytes

Programming Micro Note 20161018

Reference to pointer

Source:
Passing references to pointers in C++

Q: How do I pass a reference of pointer to a function?

void func(string*& val) {
	//...
}
{
	string s;
	func(&s);
}

this doesn't comile.

cannot convert parameter 1 from 'std::string *' to 'std::string *&'

A:
You need an actual string pointer instead of an anonymous string pointer.

string s;
string * ptr_s = &s;
func(ptr_s);

should work.