小编Jes*_*nds的帖子

C2039:Class不是Namespace的成员

法/接口/ 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();
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

法/接口/ 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 …
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
2万
查看次数

输出到几个ostreams的类(文件和控制台)

是的,我甚至不确定如何正确地制定这个; 我觉得这是一个涉及的问题.我相信有人可以帮助我.

这就是我想要做的:

  1. 有一个我可以发送东西的课程,就像这样.

    icl << "Blah blah blah" << std::endl;
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我希望能够继承std :: basic_ostream的.attach()类.

  3. 然后,这些类将能够以自己的方式格式化输出.有人可能会添加一个时间戳并写入日志,另一个可能会将其写入控制台,另一个可能会在游戏中显示它.

有人想让我开始朝着正确的方向前进吗?这是我几乎拥有的想法.

#include <vector>

class OutputMan {
    std::vector<std::basic_ostream&> m_Streams;

public:
    void attach(std::basic_ostream& os) {
        m_Streams.push_back(os);
    }
}
Run Code Online (Sandbox Code Playgroud)

问题1:我需要继承和覆盖发送什么

icl << "Blah!" << std::endl;
Run Code Online (Sandbox Code Playgroud)

到m_Streams中的每个流?

问题2:如何继承std :: basic_ostream并创建一个更改输出的类,例如,在其开头添加时间戳?我也希望这个类输出到一个文件.

c++ inheritance ostream

3
推荐指数
1
解决办法
558
查看次数

Go:函数回调返回接口的实现

我有一个处理资源解析的系统(将名称与文件路径匹配等).它解析文件列表,然后保持指向返回接口实现实例的函数的指针.

它更容易展示.

resource.go

package resource

var (
    tex_types    map[string]func(string) *Texture = make(map[string]func(string) *Texture)
    shader_types map[string]func(string) *Shader  = make(map[string]func(string) *Shader)
)

type Texture interface {
    Texture() (uint32, error)
    Width() int
    Height() int
}

func AddTextureLoader(ext string, fn func(string) *Texture) {
    tex_types[ext] = fn
}
Run Code Online (Sandbox Code Playgroud)

dds.go

package texture

type DDSTexture struct {
    path   string
    _tid   uint32
    height uint32
    width  uint32
}

func NewDDSTexture(filename string) *DDSTexture {
    return &DDSTexture{
        path:   filename,
        _tid:   0,
        height: 0,
        width:  0,
    }
}


func init() {
    resource.AddTextureLoader("dds", …
Run Code Online (Sandbox Code Playgroud)

interface callback return-type return-value go

2
推荐指数
1
解决办法
596
查看次数

抛出异常时应用程序崩溃

在我写的应用程序中,我在大多数错误处理中使用了异常.我还没有定义自己的异常类,我只做了以下几点:

namespace Mage {
    typedef std::exception Exception;
}
Run Code Online (Sandbox Code Playgroud)

这样,当我稍后定义自己的类型时,我将不必更改所有代码,这应该使用相同的接口.

也就是说,任何异常都会导致我的应用程序崩溃.考虑到上面的定义,为什么会崩溃?

void Mage::Root::initialize(Mage::String& p_log) {
    // initialize GLFW and GLEW.
    if (!glfwInit()) {
        throw new Mage::Exception("failed to initialize OpenGL");
        return;
    } else m_GLFWInitialized = true;
Run Code Online (Sandbox Code Playgroud)

无论我删除还是保留"新",它仍会崩溃.我错过了什么吗?我已经查阅了教程,但那些并没有让我更聪明.

我也在这里发现错误:

try {
    MAGE_ROOT.initialize(Mage::String("Mage.log"));
} catch (Mage::Exception& e) {
    std::cerr << e.what() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

我得到的崩溃是:

Debug Error!

Program: ...sual Studio 2010\Project\Mage3D\Binaries\Debug\Test.exe

R6010
- abort() has been called

(Press Retry to debug application)
Run Code Online (Sandbox Code Playgroud)

c++ exception

1
推荐指数
1
解决办法
6456
查看次数

Go的替代日期/时间库

Golang的time包装有其他选择吗?我无法掌握其笨重的界面和奇怪的做事方式.整体语言很棒,但这部分内容从未与我点击过.

任何人?一个非常好的,彻底的教程也可以工作(我还没有设法找到一个)

我现在要做的是goroutine每秒仅更新10次(或我设置的任何变量间隔).我还没有实现它,因为包不好玩.这是伪代码.

function GoRoutine(updatesPerSecond int) {
    interval = 1000msec / updatesPerSecond

    for {
        if enoughTimeHasPassed {
            doThings()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

time datetime go

1
推荐指数
1
解决办法
267
查看次数

自动覆盖所有链接的事件

我正在编写一个jQuery脚本,它将工具提示添加到我的Web应用程序上的特定链接.该网站不断添加新链接.我正在尝试做的是,脚本将自动遍历页面上的所有链接和新的链接.

此外,该脚本还通过更改其颜色并在其前面添加前缀图像来修改链接本身.这就是我需要继续自动寻找新链接的原因.

为了实现这一目标,我需要做些什么样的事件?

javascript anchor jquery

1
推荐指数
1
解决办法
57
查看次数

C2653:'GUI':不是类或命名空间

认真地让我紧张.这段代码工作得很好,我重新启动了IDE(Visual Studio 2010),现在突然代码变得疯狂了.错误日志是巨大的,我不知道是什么导致它,因为代码似乎非常正确.

1>ClCompile:
1>  uicont.cpp
1>c:\users\jesse\documents\visual studio 2010\projects\mage3d\mage3d\include\mage\gui\uicontext.h(21): error C2653: 'GUI' : is not a class or namespace name
1>c:\users\jesse\documents\visual studio 2010\projects\mage3d\mage3d\include\mage\gui\uicontext.h(21): error C2143: syntax error : missing ';' before '*'
1>c:\users\jesse\documents\visual studio 2010\projects\mage3d\mage3d\include\mage\gui\uicontext.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jesse\documents\visual studio 2010\projects\mage3d\mage3d\include\mage\gui\uicontext.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Run Code Online (Sandbox Code Playgroud)

还有更多,但我认为这是造成错误的原因.以下是问题最多的文件的源代码.

法/ GUI/UIContext.h

#include <OGRE/OgreString.h>
#include <OGRE/OgreOverlay.h>
#include <OGRE/OgreOverlayManager.h>

#include <vector>

#include <Mage/GUI/Frame.h>

#ifndef …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces class visual-studio-2010

0
推荐指数
1
解决办法
1386
查看次数

unsafe.Pointer到Go中的[]字节

我正在尝试为Go中的OpenGL项目编写一个截图函数,我正在使用此处的OpenGL绑定:

https://github.com/go-gl/glow

这是我用来制作屏幕截图的代码,或者说,这就是我正在做的事情:

    width, height := r.window.GetSize()
    pixels := make([]byte, 3*width*height)

    // Read the buffer into memory
    var buf unsafe.Pointer
    gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
    gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGB, gl.UNSIGNED_BYTE, buf)
    pixels = []byte(&buf) // <-- LINE 99
Run Code Online (Sandbox Code Playgroud)

这会在编译期间触发以下错误:

video\renderer.go:99: cannot convert &buf (type *unsafe.Pointer) to type []byte.
Run Code Online (Sandbox Code Playgroud)

如何转换unsafe.Pointer为字节数组?

arrays opengl pointers type-conversion go

0
推荐指数
1
解决办法
6292
查看次数