1
vote
1answer
66 views

How to convey lifetime requirements?

Usually I use std::unique_ptr to convey ownership and pass in raw pointers as parameters when no ownership is implied. However, I almost never consider a nullptr to be acceptable as an argument, so it ...
2
votes
1answer
198 views

Why function returning by Address can not be a Lvalue?

Why it is not possible to make it LValue if a function return by address (while possible in case of reference)? int* returnByAdress() { int x =20; return &x; } int& ...
21
votes
4answers
3k views

Why do C++ and Java both use the notion of “reference” but not in the same sense?

In C++ a reference argument to a function allows the function to make the reference refer to something else: int replacement = 23; void changeNumberReference(int& reference) { reference = ...
3
votes
3answers
821 views

How to initialize all your references?

I have recently taken a project with another developer, and he has a certain way of initializing his references. class Player { private: Console &console; Armor &armor1, ...
6
votes
6answers
1k views

Stroustrup and the C++ complexity admission [closed]

I heard from a friend that Bjarne Stroustroup admitted that he doesn't know entirely the C++ programming language due to its vast complexity Is it true and there's some referrable sources or is it ...
2
votes
1answer
375 views

Brief material on C++ object-lifetime management and on passing and returning values/references

I was wondering if anybody can point to a post, pdf, or excerpt of a book containing the rules for C++ variable life-times and best practices for passing and returning function parameters. Things like ...
2
votes
4answers
2k views

Need help understanding reference operator(C++) in specific functions

In the current semester at the university we are working on OOP with C++. I would like to understand the difference between a pointer and a reference operator. The differences that I understand ...
2
votes
3answers
476 views

What are pros and cons of using temporary “references”?

In C and C++ (and I guess other languages that allow taking a "reference" to an array element or something similar), when you have an array like type, accessing individual elements of such an array ...