Reference to a pointer question
- by Yogesh Arora
Please refer to the code below. In this code i am storing the const char* returned by test.c_str() into a reference. My question is Will the data be correctly refering to the contents of test. I am thinking that ptr returned by test.c_str() will be a temporary and if i bound it to a reference that reference will not be valid. Is my thinking correct
class RefPtrTest
{
std::string test;
StoringClass storingClass;
public:
RefPtrTest(): test("hello"), storingClass(test.c_str())
{
}
}
where StoringClass is
class StoringClass
{
const char*& data;
public:
StoringClass (const char*& input): data(input)
{
}
}