I was just saw code like this /* whatever */ foo(std::string const& s) { // stuff auto L = s.length(); int i{/* init based on L */}; whil ...
I was just saw code like this /* whatever */ foo(std::string const& s) { // stuff auto L = s.length(); int i{/* init based on L */}; whil ...
I write a class with template method and use it like below. This code failed with linker error : undefined reference to `void A::DoSomething<std ...
I began learning C++ this week, and currently I am reading about compound types and constant variables. Unlike in most cases, references to const supp ...
I am trying to optimize for speed of execution a piece of code using the factory design pattern. The factory will produce many objects of a class hav ...
Today I see this piece of code and I'm wondering to know what it is exactly doing this const reference in an assignment where a new object is created. ...
Since I'm a beginner in c++, some questions don't quite understand. This question came across by accident while I was reading C++ primer 5th. I hav ...
Since we can pass rvalue to function taking const left ref, void taking(const string& ref) {} taking("abc"); can we return rvalue as const lef ...
Why if Will give an UB This: will be OK? I guess that in first case temporary object expires right after end of the expression const string&am ...
How to know if you can bind a const reference T1 to T2 ? I used to think that you can bind const reference T1 to type T2 only if T2 is convertible to ...
The following code causes undefined behaviour: (because lifetime extension by const& doesn't apply here, as it's my understanding). To prevent ...
There are many existing questions about const reference (reference to const). But when there is an implicit conversion, const reference also causes a ...
I did the following as a cheap way to allow read-only access to a member container _numbers via numbers: However, doing so I see that numbers is em ...
I can't seem to figure out why the following code doesn't work: #include <array> template <long unsigned int s> void a() {} template &l ...
This has probably been already asked. Why is it allowed to assign a reference-to-const to a non-const variable? Why is this allowed int mut {0}; co ...
Consider #include <iostream> #include <utility> const auto& foo() { return std::make_pair("hi there", 2020); } int main() { ...
It is a bit confusing to me about how C++ 11 does template deduction when const references to a template parameter types are used. Consider the follow ...
I'm doing the exercises from "Programming Principles and Practice using C++" and I found a class with this member function here: where name is a ve ...
Edit: The problem has been found to be that the Wrapper class is creating copies of the BSCallFunction when passed into the MCEngine function and in t ...
I got to know that to make a friend function, friend function should be explicitly declared in enclosing scope or take an argument of its class. Howev ...
Consider the following code: These two functions correspond to two common ways to pass "in"-parameters rather than "out" or "in/out" parameters. Th ...