为什么我不能把“使用”声明内部类声明? [英] Why can't I put a "using" declaration inside a class declaration?

查看:115
本文介绍了为什么我不能把“使用”声明内部类声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解当您在头文件中使用声明时可以遇到的麻烦,所以我不想这样做。相反,我试图在类声明中使用使用(或命名空间foo = ),在头文件中键入。不幸的是我得到编译错误。似乎这将是一个有用的功能。

I understand the troubles you can get into when you put a using declaration inside a header file, so I don't want to do that. Instead I tried to put the using (or a namespace foo =) within the class declaration, to cut down on repetitive typing within the header file. Unfortunately I get compiler errors. Seems like it would be a useful feature.

#ifndef FOO_H
#define FOO_H

// This include defines types in namespace gee::whiz::abc::def,
// such as the class Hello.
#include "file_from_another_namespace.h"

// using namespace gee::whiz::abc::def; // BAD!

namespace x {
   namespace y {
      namespace z {

struct Foo {
    using namespace gee::whiz::abc::def; // Illegal.
    namespace other = gee::whiz::abc::def; // Illegal.

    // Foo(gee::whiz::abc::def::Hello &hello); // annoyingly long-winded

    Foo(other::Hello &hello); // better
    //...
};

} } } // end x::y::z namespace

#endif // FOO_H

在实际代码中,命名空间名称长得多,令人讨厌,这不是我可以改变的。

In the real code, the namespace names are much longer and annoying and it's not something I can change.

推荐答案

你能不能 typedef gee :: whiz :: abc :: def :: Hello Hello

这篇关于为什么我不能把“使用”声明内部类声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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