Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member

Tags:

c++

opengl

I'm trying to make a function that can read and compile opengl vertex and fragment shader files, but I'm getting this error:

'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member

I'm not quite sure how to fix it. Here is my code:

GLuint shader_load(const GLchar* vertex, const GLchar* fragment) {

std::string ver = file_read_all(vertex);
std::string frag = file_read_all(fragment);

const GLchar* verCode = ver.c_str;
const GLchar* fragCode = frag.c_str;

GLuint program;

GLuint verShader, fragShader;
GLint success;
GLchar log[512];

verShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(verShader, 1, &verCode, NULL);
glCompileShader(verShader);
glGetShaderiv(verShader, GL_COMPILE_STATUS, &success);

if (!success) {
    glGetShaderInfoLog(verShader, 512, NULL, log);
    std::cout << "Failed to compile Vertex Shader\n" << log << std::endl;
    return NULL;
}

fragShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragShader, 1, &fragCode, NULL);
glCompileShader(fragShader);
glGetShaderiv(fragShader, GL_COMPILE_STATUS, &success);

if (!success) {
    glGetShaderInfoLog(fragShader, 512, NULL, log);
    std::cout << "Failed to compile Fragment Shader\n" << log << std::endl;
    return NULL;
}

program = glCreateProgram();

glAttachShader(program, verShader);
glAttachShader(program, fragShader);

glLinkProgram(program);

glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success)
{
    glGetProgramInfoLog(program, 512, NULL, log);
    std::cout << "Failed to Link Shader\n" << log << std::endl;
}

glDeleteShader(verShader);
glDeleteShader(fragShader);
}

I'm using Visual Studio Community 2015 on Windows 10

like image 297
Jeremy Moyes Avatar asked Mar 03 '16 03:03

Jeremy Moyes


1 Answers

std::string::c_str is a member function, if you want to call it, you should add ().

const GLchar* verCode = ver.c_str();
                                 ~~
like image 197
songyuanyao Avatar answered Nov 26 '22 15:11

songyuanyao