引用命名空间中的结构类型
Referring to a struct type inside a namespace
是否可以在命名空间中引用结构类型(例如在sys/epoll.h中声明epoll_event)?
我试过:
#include <iostream>
#include <sys/epoll>
namespace N1 {
namespace N2 {
class C {
public:
void print() const {
std::cout << sizeof(struct epoll_event) << std::endl;
}
};
}
}
int main(int argc, char** argv) {
N1::N2::C c;
c.print();
return 0;
}
g++给了我这个错误:
nested.cpp:3:21: error: sys/epoll: No such file or directory
nested.cpp: In member function ‘void N1::N2::C::print() const’:
nested.cpp:23: error: invalid application of ‘sizeof’ to incomplete type ‘N1::N2::epoll_event’
由于某些原因,那些属于 std 的"全局"结构不会出现上述问题(我尝试将"struct epoll_event"替换为"struct tm",并且工作正常)。
所以2个问题:
1. 引用那些"全局"非 std 结构的正确方法是什么?
2. 为什么编译器(至少 g++ 4.4.x)对那些"全局"std 结构的处理方式不同?
提前谢谢。
你只需要包含正确的头文件,否则你的代码是正确的。sys
中有epoll.h
,但没有epoll
标题
更新
#include <sys/epoll>
自
#include <sys/epoll.h>
相关文章:
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- <badref> 当使用 CallInst::CreateMalloc 作为结构类型时
- 给定一个C++嵌套的私有结构类型,是否有从文件范围静态函数访问它的策略
- 为什么"具有常量成员的结构"类型的指针不能指向"具有非常量成员的结构"?
- 查找声明为结构类型 C++ 的数组末尾
- C++ - 将结构类型的数组传递给用户定义的函数
- PowerShell 使用结构类型参数调用 C++ DLL 的导出函数
- NTTP 的结构类型:为什么所有成员都必须是公共的?
- 当我尝试访问结构类型时,我收到 std::bad_variant_access 异常
- 承诺可以使用结构类型吗?
- 填充模板化结构类型的结构成员
- 如何为结构类型变量赋值
- 在 c++ 中将结构类型转换为无符号字符*
- 在 c++ 中将一种结构类型分配给另一种类型
- 如何访问在 c++ 中在类内声明的结构类型指针变量?
- 确定输入"conscalc: calc"的类型时出错。不能联合编码器。具有不同字段集的结构类型
- 无法将结构类型的标识符设置为 nullptr;
- 结构类型成员的默认构造函数中的默认参数
- 如何在执行期间终止(或返回)具有结构类型的自动函数
- 在 stl 中迭代结构类型的队列