Skip to content

Logging::operator<<: change argument type from T& to const T& #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jini-zh
Copy link
Contributor

@jini-zh jini-zh commented Aug 3, 2023

Non-const references cannot be bound to functions results and literals, so the code

Logging log;
try {
  throw std::runtime_error("message");
} catch (std::exception& e) {
  log << e.what() << '\n';
}

ends up calling std::ostream::operator<< both for e.what() and '\n' and produces nothing in the output.

Non-const references cannot be bound to functions results and literals,
so the code
```C++
Logging log;
try {
  throw std::runtime_error("message");
} catch (std::exception& e) {
  log << e.what() << '\n';
}
```
ends up calling `std::ostream::operator<<` both for `e.what()` and
`'\n'` and produces nothing in the output.
@brichards64
Copy link
Contributor

please heck if still relavent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants