Message from C, C++ talks

June 2019

— But learning opengl 2.0 is useless ¯\_(ツ)_/¯

— Ok

— /startMissRose_bot

— Heya :) PM me if you have any questions on how to use me!


const char* vertex = readFile(vertexFile).c_str();
here you're assigning the pointer of the std::string that the function returned, but that object is then destroyed and accessing that memory is no longer guaranteed to have the string you wanted

— Whats the best to use then?

— Why not use std::string instead of those char*'s?

— GlShaderSource needs a char*

— Give it the c_str of vertex and fragment

— I'd assume it'd be smart enough that it knows it has to copy the char* you pass it

— Is it possible to keep a return in memory from a func

— Yes

— Depends

— Use heap memory

— If you put it in memory yeah. like
std::string vertex = readFile(vertexFile);
would copy the std::string object back into memory

Message permanent page