This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
what’s the meaning of *&
what * &pSth mean?
is this a pointer or a ref?
Why/When we need that?
--code--
ClassName::GetSth(TypeName* &pSth)
{
//some code
}
It means "reference to pointer to Typename".
TypeName* &pSth is a reference to TypeName pointer.
Equivalent syntax in C is TypeName** pSth
Related
This question already has answers here:
What does '&' do in a C++ declaration?
(7 answers)
Closed 2 years ago.
What is the difference between int &r and int r?
I'm new to this
First keep in mind that int& r and int &r are syntactically the same thing: r is a variable of type int&. So r is an integer reference.
To learn more about references in C++, there are plenty of online guides. Here's one: https://www.embedded.com/an-introduction-to-references/
This question already has answers here:
gsl::not_null<T*> vs. std::reference_wrapper<T> vs. T&
(2 answers)
Closed 4 years ago.
I have a class that has a reference field that needs to be reassigned. But unlike pointer, it can't be null.
Requirements:
Reference syntax: field.foo() to invoke method, instead of field->foo();
Re-assignable: foo = new_val; // OK
Is it possible to model model this concept in C++?
Yes. Use a std::reference_wrapper<T> instead of a raw reference.
This question already has answers here:
Typedef function pointer?
(6 answers)
Closed 6 years ago.
I ran across a line of code that looks like the following:
typedef Foo* (*CREATE_BAR)(uint32_t);
How exactly does this work? What is happening in this code?
It's a function pointer type named CREATE_BAR which accepts a uint32_t argument and returns a Foo*. It could hold a pointer to any such function.
It is a type for a pointer on function returning Foo*, and taking uint32_t
In c++11, it would be
using CREATE_BAR = Foo* (*)(uint32_t);
This question already has answers here:
What does `*&` in a function declaration mean?
(8 answers)
Closed 8 years ago.
I am Converting a C++ code into C program. I come across a function that takes void draw(char *&a). how to write this function *& in C program. I tried using same *&a but it is showing , (...etc expected. Please help.
Thanks
There is no pass by reference in C. Therefore you need to change the function declaration to
void draw(char **a)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why cast an unused value to void?
for this C++ code:
MyClass::myFunc(int val)
{
//some code
(void)val;
//somecode
}
why may we need to cast val to void without being assigned to another variable ?
This is done to shut up the compiler, warning about an unused variable.