Tushar
Yeah.. I know C
Tushar
Basic C
Tushar
Including arrays, structure and pointers
Dima
this does not indicate that you know c
Anonymous
To get basics of C++ read some book
Like Stephen Prata "The Primer Plus"
Anonymous
Anonymous
(Note: He left out functions)
Anonymous
(From his knowledge list)
Anonymous
Why shouldn't I use return by address for
-> When returning a large struct or class that was passed by reference (use return by reference)
Tushar
Ok, thanks
Anonymous
We just answered that.
Anonymous
Ajay
Anonymous
Look above.
Anonymous
We just answered that.
You said "so you don't have to use the address-of (&) operator on the reference you were passed."
Anonymous
but is there any problem in using the & operator
Anonymous
?
Anonymous
No, but why do that, when you can instead safely return the reference.
Anonymous
Anonymous
but is it strictly NO for returning the address?
Anonymous
Anonymous
You cannot return a pointer to an object which was created inside your function
Anonymous
Well, you can, of course
But accessing a value through this pointer is undefined behavior
Anonymous
And same thing with returning references
Anonymous
He means returning the pointer to an object thatw as passed as a reference to the fucntion iirc
Anonymous
Here is his original question.
Anonymous
I read this:
When not to use return by address:
1. When returning variables that were declared inside the function or parameters that were passed by value (use return by value)
2. When returning a large struct or class that was passed by reference (use return by reference)
Kindly explain the reason for the second point.
Anonymous
What does "iirc" mean?
Anonymous
if I recall correctly
Anonymous
Ok, so
Consider you need a function that modifies a vector. There's no need to return anything via return statement. You simply pass the vector to a function by a non-const ref and that's it
void modify_vector(std::vector<int>& vec);
Anonymous
return by address means returning the address of the entity and catching it in a pointer outside
Dima
yessss
Anonymous
What's wrong, Dima?
Vladimir
Anonymous
Anonymous
I doubt that.
Anonymous
Vladimir
Anonymous
Anonymous
Anonymous
To your 2nd point
Anonymous
Undefined behaviour is fun sometimes, I agree.
Anonymous
This is my answer
Yeah !! Thanks. Now, I realize it was a silly question to return by address in that circumstance.
Thanx bro
Anonymous
I wanted a resource to learn about how cpp streams. A good resource.
Anyone?
Anonymous
Anonymous
something that explains well and is understandable
Vladimir
Anonymous
Of course one should.
Vladimir
I mean it's not forbidden to return pointers
Anonymous
But then again returning huge structs by value isn't forbidden as well, but not very wise ;)
Anonymous
I wanted a resource to learn about how cpp streams. A good resource.
Anyone?
Dima
cplusplus.com
Vladimir
Anonymous
cplusplus.com
That doesn't give detailed explantion
Anonymous
You can always open the header file and read it for yourself ^.^
Dima
www.google.com
Anonymous
MRFERBO
😊
Anonymous
or you can use www.ecosia.org
Anonymous
I guess.
Anonymous
Anonymous
I personally heard cppreference is better, not sure thouigh. I like the minimalist design of cppref more.
Dima
unreadable way
Anonymous
Dima
I actually mixed up these two sites, I mean cppreference
Dima
but cplusplus is fine too
Anonymous
At least header files are more readable than Brainf*ck...but it's not hard to be better than Brainf*ck either.
Anonymous
I'm sorry for the people who have to maintain those.
Anonymous
what does this mean?
Anonymous
"assigning a value to a const reference can extend the lifetime of that value"
Anonymous
Anonymous
https://www.learncpp.com/cpp-tutorial/74a-returning-values-by-value-reference-and-address/
Anonymous
Anonymous
Well, that must have meant sth.