gpt4 book ai didi

c++ - C2039 : Class is not a member of Namespace

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:56:37 25 4
gpt4 key购买 nike

Mage/Interface/Context.h

#pragma once

#include <Mage/Interface/Element.h>
#include <Mage/Renderer/RenderingContext.h>
#include <Mage/Renderer/VertexBuffer.h>

#include <glm/glm.hpp>

namespace Mage {
namespace Interface {
class Context {

protected:
RenderingContext* ctx;
VertexBuffer* vbo;
glm::mat4 projection;
Mage::Interface::Frame* uiParent;

public:
Context(RenderingContext* ctx);
~Context();

void render();
Mage::Interface::Frame* createFrame();
};
}
}

Mage/Interface/Element.h

#pragma once

#include <vector>

#include <Mage/Interface/Context.h>

#include <glm/glm.hpp>

namespace Mage {
namespace Interface {
class Element {

protected:
Mage::Interface::Context* ctx;
std::vector<Element*> children;
glm::vec3 position;
float scale;

public:
virtual void draw();

void attach(Element* child) {
this->children.push_back(child);
}

inline glm::vec3 getPosition() {
return this->position;
}

float getScale() {
return this->scale;
}
};

// Frame is an untextured, single colour quad. Frame may contain other
// Elements.
class Frame : public Element {

public:
Frame();
Frame(glm::vec3 pos);
Frame(float width, float height);
Frame(glm::vec3 pos, float width, float height);
};
}
}

这给了我以下错误:

Error   C2039   'Context': is not a member of 'Mage::Interface' Mage2D  c:\users\jesse\documents\visual studio 2015\projects\mage2d\include\mage\interface\element.h    14

Error C2238 unexpected token(s) preceding ';' Mage2D c:\users\jesse\documents\visual studio 2015\projects\mage2d\include\mage\interface\element.h 14

Error C2143 syntax error: missing ';' before '*' Mage2D c:\users\jesse\documents\visual studio 2015\projects\mage2d\include\mage\interface\element.h 14

Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int Mage2D c:\users\jesse\documents\visual studio 2015\projects\mage2d\include\mage\interface\element.h 14

当我取出 Mage::Interface::Context* ctx 时,代码编译正常。我想我一定是漏掉了一个分号,但我看不到它 - 这一切对我来说似乎都很好。

最佳答案

你有一个循环依赖。 Element.h 包含 Context.h,而 Context.h 包含 Element.h,这是行不通的。

解决这个问题的方法是转发声明类型,而不是尽可能包含它们的 header ,这也会减少编译时间。

关于c++ - C2039 : Class is not a member of Namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30819201/

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