gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 02:06:49 25 4
gpt4 key购买 nike

访问头文件中的 namespace 似乎有问题。最好的解释方法是通过示例:


我在执行此操作时遇到编译器错误:

游戏.h:

#pragma once

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

游戏.cpp:

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

#include "Game.h"

这是错误:

'glm' is not a class or namespace name
'projection': unknown override specifier
missing type specifier - int assumed. Note: C++ does not support default-int

但是,这样做没问题:

游戏.h:

#pragma once

struct Game
{
//some other stuff here
};

游戏.cpp:

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

#include "Game.h"

glm::mat4 projection;

令我难过的是,尽管它适用于 cpp 文件,但在头文件中找不到 namespace 。

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

最佳答案

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

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

关于c++ - 从头文件中的命名空间访问类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com