为什么这个错误变成(C2664错误C ++ Visual Studio)

why this error become (C2664 error c++ Visual Studio)

本文关键字:错误 Visual C2664 Studio 为什么      更新时间:2023-10-16

我正在尝试修改一个程序.在2015 Visual Studio中实现。 在Visual Studio 2019中打开项目后,会出现以下类型的许多错误。

Severity  Code    Description Project File    Line    Suppression State
Error C2664    'Model::Model(Model &&)': cannot convert argument 1 from 'const > char [24]' to 'GLchar *' OpenGl  
Severity  Code    Description Project File    Line    Suppression State
Message        Conversion from string literal loses const qualifier (see /Zc:strictStrings)   OpenGl  

该行中形成的错误:

// Create a GLFWwindow object that we can use for GLFW's functions
 GLFWwindow *window = glfwCreateWindow( WIDTH, HEIGHT, "LearnOpenGL", 
 nullptr, nullptr );
if ( nullptr == window )
{
    std::cout << "Failed to create GLFW window" << std::endl;
    glfwTerminate( );
    return EXIT_FAILURE;
}
glfwMakeContextCurrent( window );
glfwGetFramebufferSize( window, &SCREEN_WIDTH, &SCREEN_HEIGHT );
// Set the required callback functions
glfwSetKeyCallback( window, KeyCallback );
glfwSetCursorPosCallback( window, MouseCallback );
// GLFW Options
glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED );
// Set this to true so GLEW knows to use a modern approach to retrieving 
function pointers and extensions
glewExperimental = GL_TRUE;
// Initialize GLEW to setup the OpenGL Function pointers
if ( GLEW_OK != glewInit( ) )
{
    std::cout << "Failed to initialize GLEW" << std::endl;
    return EXIT_FAILURE;
}
// Define the viewport dimensions
glViewport( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
// OpenGL options
glEnable( GL_DEPTH_TEST );
// Setup and compile our shaders
Shader shader( "res/shaders/modelLoading.vert", 
 "res/shaders/modelLoading.frag" );
// Load models
Model ourModel("res/models/nanosuit.obj");
// Draw in wireframe
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glm::mat4 projection = glm::perspective( camera.GetZoom( ), ( float 
)SCREEN_WIDTH/( float )SCREEN_HEIGHT, 0.1f, 100.0f );
// Game loop
while( !glfwWindowShouldClose( window ) )
{
    // Set frame time
    GLfloat currentFrame = glfwGetTime( );
    deltaTime = currentFrame - lastFrame;
    lastFrame = currentFrame;
    // Check and call events
    glfwPollEvents( );
    DoMovement( );
    // Clear the colorbuffer
    glClearColor( 0.05f, 0.05f, 0.05f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    shader.Use( );
    glm::mat4 view = camera.GetViewMatrix( );
    glUniformMatrix4fv( glGetUniformLocation( shader.Program, "projection" 
       ), 1, GL_FALSE, glm::value_ptr( projection ) );
     glUniformMatrix4fv( glGetUniformLocation( shader.Program, "view" ), 
       1, 
    GL_FALSE, glm::value_ptr( view ) );
    // Draw the loaded model
    glm::mat4 model;
    model = glm::translate( model, glm::vec3( 0.0f, -1.75f, 0.0f ) ); // 
  Translate it down a bit so it's at the center of the scene
    model = glm::scale( model, glm::vec3( 0.2f, 0.2f, 0.2f ) ); // It's a 
  bit too big for our scene, so scale it down
     glUniformMatrix4fv( glGetUniformLocation( shader.Program, "model" ), 
   1, GL_FALSE, glm::value_ptr( model ) );
    ourModel.Draw( shader );
    // Swap the buffers
    glfwSwapBuffers( window );
}
glfwTerminate( );
return 0;
}
         // Moves/alters the camera positions based on user input
    void DoMovement( )
          {
// Camera controls
if ( keys[GLFW_KEY_W] || keys[GLFW_KEY_UP] )
{
    camera.ProcessKeyboard( FORWARD, deltaTime );
}
if ( keys[GLFW_KEY_S] || keys[GLFW_KEY_DOWN] )
{
    camera.ProcessKeyboard( BACKWARD, deltaTime );
}
if ( keys[GLFW_KEY_A] || keys[GLFW_KEY_LEFT] )
{
    camera.ProcessKeyboard( LEFT, deltaTime );
}
if ( keys[GLFW_KEY_D] || keys[GLFW_KEY_RIGHT] )
{
    camera.ProcessKeyboard( RIGHT, deltaTime );
    **strong text**  }
}
       // Is called whenever a key is pressed/released via GLFW
    void KeyCallback( GLFWwindow *window, int key, int scancode, int 
          action, int mode )
         {
if ( GLFW_KEY_ESCAPE == key && GLFW_PRESS == action )
{
    glfwSetWindowShouldClose(window, GL_TRUE);
}
if ( key >= 0 && key < 1024 )
{
    if ( action == GLFW_PRESS )
    {
        keys[key] = true;
    }
    else if ( action == GLFW_RELEASE )
    {
        keys[key] = false;
    }
}
}
   void MouseCallback( GLFWwindow *window, double xPos, double yPos )
     {
  if ( firstMouse )
{
    lastX = xPos;
    lastY = yPos;
    firstMouse = false;
}
GLfloat xOffset = xPos - lastX;
GLfloat yOffset = lastY - yPos;  // Reversed since y-coordinates go from 
  bottom to left
lastX = xPos;
lastY = yPos;
camera.ProcessMouseMovement( xOffset, yOffset );
    }

错误正好在 荷载模型 Model ourModel("res/models/nanosuit.obj"(;

您可以将模型名称作为非常量 C 字符串传递:

char tmp[] = "res/models/nanosuit.obj";
Model ourModel(tmp);