I have code that does
if(x>5){
vector<int> a;
return a;
}
But i'm curious if theres a way to do this return in one line such like:
if(x>5){
return vector<int> a;
}
This will work as expected:
return vector<int>();
This creates an object and returns one at the same time. Since the object has not been created without any name, it is known as anonymous object.
Hence you can modify your code, without assigning a name to the variable, like this:
if(x>5){
return vector<int>();
}
You can do:
return {};
This will create a anonymous object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With