My main language is C#, and I'm learning opengl with scarce c++ background.
// readShaderSource returns const string
// no warning
auto vShaderStr = readShaderSource("vshader.glsl");
auto vShaderSource = vShaderStr.c_str();
// dangling pointer warning
auto vShaderSource = readShaderSource("vshader.glsl").c_str();
What I thought about dangling pointer is something like this:
int* a()
{
auto a = 10;
return &a
// a dies here, so &a becomes dangling pointer
}
which does not seem to be the case.
Why should I have to go through string variable? Isn't it okay to directly access member function? Is there something to do with return value optimization? I'm pretty confused...