OpenGL ERROR E0310

FaclonDev 1 Reputation point
2021-08-21T10:09:34.44+00:00

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 errors with it

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,757 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 118K Reputation points
    2021-08-21T16:13:22.517+00:00

    I think that you must change the definition of default argument:

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

    This maybe requires corresponding changes to other functions. It is probably a good idea to use const if geometryFile is a read-only string. Check if const can be added to other parameters too.

    By the way, instead of 'if(geometryFile != "")', which is not always correct, you can write 'if(*geometryFile)' or 'if(strlen(geometryFile) != 0)'.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.