有没有办法用#define替换长名称空间? [英] Is there a way to substitute long namespaces with #define?

查看:86
本文介绍了有没有办法用#define替换长名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个很长的名称空间,我不想一直输入.但是我也不想使用using namespace ....我可以为此使用#define吗?

Suppose I have a very long namespace, which I don't want to type in all the time. But I don't want to use using namespace ... either. Can I use #define for this?

示例:

#define glm::quat glm::gtc::quaternion

class Camera
{
protected:
    glm::quat m_mRotation;
};

我不想使用using,因为我认为glm ::部分也将消失.所以我想保留glm部分,而不要保留整个gtc :: quaternion部分.现在尝试此操作时,出现以下错误:

I don't want to use the using, because the glm:: part will be gone as well, I think. So I would like to keep the glm part, but not the totally long gtc::quaternion part. When I try this now, I get the following error:

错误1错误C2008:':':宏定义中未预料到

Error 1 error C2008: ':' : unexpected in macro definition

推荐答案

您不需要定义,请使用名称空间别名:

you don't need a define, use a namespace alias:

namespace glm_quat = glm::gtc::quaternion::quat;

或者如果您希望别名确实在glm命名空间中,请将其放在此处:

or if you want the alias to be really in the glm namespace, put it there:

namespace glm {
  namespace quat = gtc::quaternion::quat;
}

这篇关于有没有办法用#define替换长名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆