比较值与结构体成员的问题
Problems comparing value to member of a struct
这个问题是关于重定义和枚举符
我的c++编译器给出以下警告和错误:
1>forgelibsourcesocket.cpp(145): warning C4832: token '.' is illegal after UDT 'Forge::AddressFamily'
1> forgelibincludeforgesocket.h(70) : see declaration of 'Forge::AddressFamily'
1>forgelibsourcesocket.cpp(145): error C2275: 'Forge::AddressFamily' : illegal use of this type as an expression
1> forgelibincludeforgesocket.h(70) : see declaration of 'Forge::AddressFamily'
1>forgelibsourcesocket.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
是struct的静态成员。 INet
是AddressFamily
的静态成员,所以需要
AddressFamily::INet
您应该尝试这样访问静态成员:
AddressFamily::INet
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- constexpr构造函数需要常量成员函数时出现问题
- 使用静态成员声明类时遇到问题
- 尝试将向量初始化为类成员时出现问题
- 当成员值从指针更改为非指针时,C++常量问题
- 常量公共成员有什么问题?
- 修改C++结构的特征成员时出现问题
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- 成员函数中的迭代器出现问题
- 为什么在分配给成员变量之前获取unique_ptr的返回是一个问题?
- 没有'str'成员在 GCC 和 Clang 'std::basic_ostream<char>',但 MSVC 没有问题
- 关于在成员重载中使用 std::move() 的问题
- 在C++中实现类似 python "map"函数的问题:调用类成员函数
- 消除 C++ 中的菱形问题以访问顶级成员
- 使用 Swig 在成员中包装具有互斥锁的 C++ 类时出现问题
- (2 问题)"类"类型重新定义(即使 #pragma 一次),以及静态函数内的静态成员对象初始化?
- OpenCV C++ Mat 类行和列 - 它们是成员变量(和相关问题)吗?
- C++关于类成员的问题
- 遇到C++方形类的问题. 成员函数实现和声明
- 问题:成员与读/写