c ++ typedef另一个类的枚举? [英] c++ typedef another class's enum?

查看:121
本文介绍了c ++ typedef另一个类的枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:

  struct A 
{
enum A_enum
{
E0,
E1,
E2
};
};

struct B
{
typedef A :: A_enum B_enum;
bool test(B_enum val)
{
return(val == E1); // error:E1undeclared identifier
}
};

我特别不想说 A :: E1 。如果我尝试 B_enum :: E1 ,我收到一个警告,它是非标准。是否有一个很好的方法来做这样的事情?

解决方案

我认为A应该是一个命名空间而不是一个结构。 / p>

So here's my problem:

struct A
{
    enum A_enum
    {
        E0,
        E1,
        E2
    };
};

struct B
{
    typedef A::A_enum B_enum;
    bool test(B_enum val)
    {
        return (val == E1); // error: "E1" undeclared identifier
    }
};

I specifically do not want to say A::E1. If I try B_enum::E1 I receive a warning that it is nonstandard. Is there a good way to do something like this?

解决方案

I reckon that A should be a namespace instead of a struct.

这篇关于c ++ typedef另一个类的枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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