zeboidlund
zeboidlund

Reputation: 10137

How to pass a char pointer by address to be accepted to char**?

I have a struct, known as Shader, which holds the following information:

struct Shader {
    enum ValueType{ VT_Attribute, VT_Uniform, VT_Varying };
    GLuint Memory;
    GLenum Type;
    char* Source;
    char* Name;
    std::map< Shader::ValueType, float* > Values;
};

Yet, if I do something like:

glShaderSource( shaderMem, 1, &shader.Source, NULL );

I get the following error:

error: invalid conversion from 'char* const*' to 'const char**'

Why is this happening?

Upvotes: 0

Views: 164

Answers (1)

K-ballo
K-ballo

Reputation: 81349

It happens because shader is const at that point. Assuming glShaderSource won't attempt to write the contents of its 3rd argument, then you can const_cast the const away:

glShaderSource( shaderMem, 1, const_cast< char** >( &shader.Source ), NULL );

Upvotes: 4

Related Questions