c++ - 将值与结构成员进行比较的问题

标签 c++ struct comparison constants

此问题是对以下问题的跟进: Redefinition and Enumerator

我的 C++ 编译器给出以下警告和错误:

1>forgelib\source\socket.cpp(145): warning C4832: token '.' is illegal after UDT 'Forge::AddressFamily'
1>          forgelib\include\forge\socket.h(70) : see declaration of 'Forge::AddressFamily'
1>forgelib\source\socket.cpp(145): error C2275: 'Forge::AddressFamily' : illegal use of this type as an expression
1>          forgelib\include\forge\socket.h(70) : see declaration of 'Forge::AddressFamily'
1>forgelib\source\socket.cpp(145): error C2228: left of '.INet' must have class/struct/union

这是 socket.cpp(145):

void Forge::InternetHost::validHostEntity(hostent* he) {
    if (he->h_addrtype != AddressFamily.INet || he->h_length != 4) { // <--145
        throw new Forge::SocketException("Address family mismatch.");
    }
}

这是定义:

struct AddressFamily {
    static const Forge::Int Unspecified = AF_UNSPEC;
    static const Forge::Int UNIX = AF_UNIX;
    static const Forge::Int INet = AF_INET;
    static const Forge::Int IPX = AF_IPX;
    static const Forge::Int AppleTalk = AF_APPLETALK;
    static const Forge::Int INet6 = AF_INET6;
};

我是否遗漏了一些非常明显的东西?

最佳答案

应该是

he->h_addrtype != AddressFamily::INet

因为 INet 是结构的静态成员。

关于c++ - 将值与结构成员进行比较的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16811503/

相关文章:

c++ - 正确使用 cin 对象?

python - 加速范围内的迭代并比较值

c++ - C++ 引用/指针语法的替代方法

c++ - 分割 64 位值以适合 double 参数类型

c - 有没有办法实现这个二叉搜索树功能?

c++ - 嵌套结构和数组 C++

c - 在 C 中实现 FIFO 队列

c++ - ImageMagick 和 GraphicsMagick 有什么区别?

r - 文本比较中adist函数的问题

C++ 矩阵乘法不产生正确的输出