I am trying to the following in C++ without using std::string. Here is the code I am trying to use and I would like to not use any deprecated futures.
void Application::_check_gl_error(const char* file, int line)
{
GLenum err(glGetError());
while (err != GL_NO_ERROR) {
char* error;
switch (err) {
case GL_INVALID_OPERATION:
error = "INVALID_OPERATION";
break;
}
std::cerr << "Error: " << err << " GL_" << error << " - " << file << ":" << line << std::endl;
}
}
I have read here that in C++ using char* without const and pointing to a string is deprecated.
You should also push the warning level of your compiler up a notch: then it will warn that your first code (i.e. char* str = "name") is legal but deprecated.
however, if I declare const char* error in every case, I get an error in the call to std:cerr that says error: Identifier "error" is not defined
Is there a way for be to conditionally set the value of error here or make it visible for the call to std::cerr?
EDIT:
I like the idea of returning a const char* however, that would require calling another function from within check_gl_error to print out the results. I am hoping to avoid that step.