reference-binding Questions
2
Solved
Consider the following code: (https://godbolt.org/z/8W699x6q6)
int* p;
const int*&& r = static_cast<int*&&>(p);
Note: const int*&& is an rvalue reference to a pointer...
Neff asked 15/9, 2023 at 20:20
1
Solved
I have the following code
#include <iostream>
void foo(const int* const &i_p) {
std::cout << &i_p << std::endl;
}
int main () {
int i = 10;
int* i_p = &i;
std::...
Sartin asked 15/9, 2023 at 17:30
6
Solved
Consider the follow code:
#include <iostream>
class Data{
public:
Data() = default;
Data(Data const&) = delete;
Data(int) {
}
};
int main(){
int a = 0;
const std::string& rs ...
Hersey asked 20/1, 2020 at 9:17
3
Is it ok to return default argument's value by const reference like in the examples below:
https://coliru.stacked-crooked.com/a/ff76e060a007723b
#include <string>
const std::string& fo...
Sociable asked 1/11, 2019 at 17:42
2
Solved
consider something like this:
#include <iostream>
struct C {
C(double x=0, double y=0): x(x) , y(y) {
std::cout << "C ctor " << x << " " <<y << " " << ...
Fidelity asked 10/9, 2019 at 7:32
2
Solved
Consider the following code:
#include <iostream>
float func(char const & val1, unsigned int const & val2)
{
return val1 + val2;
}
int main() {
double test1 = 0.2;
double test2 =...
Merrifield asked 12/6, 2019 at 15:57
1
Solved
Below is the code snippet:
#include <iostream>
using namespace std;
struct B{
int b;
~B(){cout <<"destruct B" << endl;}
};
B func(){
B b;
b.b = 1;
return b;
}
int main(){
c...
Runnels asked 26/5, 2018 at 12:13
3
Solved
I know that const reference prolongs the life of a temporary locally. Now I am asking myself if this propriety can be extended on a chain of temporary objects, that is, if I can safely define:
std...
Legging asked 2/5, 2016 at 12:35
0
Consider the following case
struct A {
operator int();
};
int &&x = A();
The spec says at http://eel.is/c++draft/dcl.init.ref#5 about whether the reference binding is direct or indirec...
Receivership asked 22/11, 2015 at 14:36
2
Solved
I'm implementing some C++ static analysis rules, and one of them prohibits a function from returning a reference or pointer to a reference parameter of the function, i.e. the following are all non-...
Perdita asked 18/7, 2012 at 9:39
1
Solved
Lets take a look to this two functions:
std::string get_string()
{
std::string ret_value;
// Calculate ret_value ...
return ret_value;
}
void process_c_string(const char* s)
{
std::cout <&...
Spreadeagle asked 26/1, 2012 at 13:27
1
© 2022 - 2025 — McMap. All rights reserved.