I have this code example:
struct A
{
bool test() const
{
return false;
}
};
template <typename T = A>
class Test
{
public:
Test(const T& t = T()) : t_(t){}
void f()
{
if(t_.test())
{
}
}
private:
const T& t_;
};
int main()
{
Test<> a;
a.f();
}
Mostly, the constructor bothers me Test, where I save the reference to the constant in a temporary variable and use it in the method f. Will the temporary object reference remain valid inside f?
source
share