C++ 从头文件中的命名空间访问类型

C++ 从头文件中的命名空间访问类型,c++,C++,访问头文件中的名称空间似乎有问题。最好的解释方法是举例说明: 执行此操作时,我收到一个编译器错误: 游戏h: #pragma once struct Game { //some other stuff here private: glm::mat4 projection; }; #pragma once struct Game { //some other stuff here }; Game.cpp: #include <glm/glm.hpp> #include

访问头文件中的名称空间似乎有问题。最好的解释方法是举例说明:


执行此操作时,我收到一个编译器错误:

游戏h:

#pragma once

struct Game
{
//some other stuff here
private:
    glm::mat4 projection;
};
#pragma once

struct Game
{
//some other stuff here
};
Game.cpp:

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "Game.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "Game.h"

glm::mat4 projection;

但是,这样做很好:

游戏h:

#pragma once

struct Game
{
//some other stuff here
private:
    glm::mat4 projection;
};
#pragma once

struct Game
{
//some other stuff here
};
Game.cpp:

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "Game.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "Game.h"

glm::mat4 projection;
#包括
#包括
#包括“Game.h”
glm::mat4投影;
让我感到困惑的是,名称空间在头文件中找不到,尽管它在cpp文件上工作


Visual Studio识别出名称空间存在(编辑器中没有下划线),但当我编译它时,它突然不存在。

它在头文件中不可用,因为您没有包含它:

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#包括
#包括

看起来您复制了经过大量编辑的代码。你在这里复制的东西很好用。可能的错误原因是使用预编译头
stdafx.h
。我没有使用预编译头。我应该吗?