OpenGL ERROR E0310

default argument of type "const char *" is incompatible with parameter of type "char *"

My code:
Shader(char* vertexFile, char* fragmentFile, char* geometryFile = "")
{
GLuint vertexShader = 0;
GLuint geometryShader = 0;
GLuint fragmentShader = 0;


vertexShader = loadShader(GL_VERTEX_SHADER, vertexFile);

if(geometryFile != "")
geometryShader = loadShader(GL_GEOMETRY_SHADER, geometryFile);

fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentFile);

this->linkProgram(vertexShader, geometryShader, fragmentShader);


//END
glDeleteShader(vertexShader);
glDeleteShader(geometryShader);
glDeleteShader(fragmentShader);

glUseProgram(0);

}
I had the same code on my other project and I had no issues. Any ideas?
Last edited on
 
if(geometryFile != "")


You can't do this type of comparison with c-style strings. Try:

 
if (geometryFile && *geometryFile)


However, the issue is:

 
Shader(char* vertexFile, char* fragmentFile, char* geometryFile = "")


You are trying to default initialise geometryFile (type char* ) to "" - which is of type const char *. Try:

 
Shader(char* vertexFile, char* fragmentFile, const char* geometryFile = "")


However, a more usual way to default initialise a char* is to set to nullptr:

 
Shader(char* vertexFile, char* fragmentFile, char* geometryFile = nullptr)


If the null-terminated strings pointed to by vertexFile and fragmentFile aren't changed, then these should also be passed as const:

 
Shader(const char* vertexFile, const char* fragmentFile, const char* geometryFile = "")

Last edited on
Ah very useful information thank you Sir
Topic archived. No new replies allowed.