简体   繁体   中英

'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 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

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

const GLchar* verCode = ver.c_str();
                                 ~~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM