#"Undeclared identifier" but I have included corresponding header

3 messages · Page 1 of 1 (latest)

lethal sierra
#

I use CMake to build the project in Visual Studio 2022.
This is the project structure. I picked out the major files

  • Sources
    • main.cpp
    • Forms
    • Header
      • globalVar.h
    • Module
      • globalVar.cpp

I declared the global variable in globalVar.h and defined it in globalVar.cpp

// globalVar.h

#ifndef WIND_GLOBAL_VAR
#define WIND_GLOBAL_VAR
    #include <QOpenGLFunctions_4_5_Core>
    #include <QVector3D>
    #include <QVector4D>
    extern QOpenGLFunctions_4_5_Core* gl;
    extern QVector3D _origin;
    extern QVector3D _front;
    extern QVector3D _right;
    extern QVector3D _up;
#endif
//globalVar.cpp

#include "../Header/globalVar.h"
QOpenGLFunctions_4_5_Core *gl = new QOpenGLFunctions_4_5_Core();
QVector3D _origin(0.0f, 0.0f, 0.0f);
QVector3D _front(0.0f, 0.0f, 1.0f);
QVector3D _right(1.0f, 0.0f, 0.0f);
QVector3D _up(0.0f, 1.0f, 0.0f);

Then in main.cpp I include globalVar.h
But the compiler error, it reported **error C2065: "_up": undeclared identifier **

I don't know if this is my misuse of global variables or something else.

visual cloakBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lethal sierra
#

!solved