So I wonder whether the following is allowed:
#include <iostream>
class Foo {
public:
Foo(const bool& ref) : ref(ref) {}
const bool& ref;
};
int main()
{
Foo foo(true);
std::cout << foo.ref << "\n";
return 0;
}
So basically I want to store an rvalue as a const lvalue reference member in a class. The question Why is it allowed to pass R-Values by const reference but not by normal reference? says this is allowed when passing the rvalue reference. But I wonder if it's okay to keep that const reference around.