本文介绍了C ++包括为size_t的Linux / types.h中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个C ++包装(添加面向对象)围绕C库(其中我是作者,即我可以根据需要有应用更改)。 C库定义了一些结构即使用为size_t 作为在的Linux / types.h中定义,因为它与接口内核。

I am trying to create a C++ wrapper (adding object orientation) around a C library (of which I am the author, i.e. I can apply changes there if needed). The C library defines some structs that make use of size_t as defined in linux/types.h since it interfaces with the kernel.

我现在想包括C库在我尝试在C ++库源的标题(定义结构)。但是,如果我这样做,编译器告诉我,

I am now trying to include the header of the C library (that defines the struct) in the sources of my attempt at a C++ library. However, if I do so, the compiler tells me that

为size_t 没有指定类型

什么是获得<$ C $从的Linux / types.h中进入为size_t 的正确方法C> C ++ ?

What is the correct way to get access to size_t from linux/types.h in C++?

P.S:头文件包含 #IFDEF _cplusplus的externC{#ENDIF

P.S.: The header file contains a #ifdef _cplusplus extern "C" { #endif block

推荐答案

不要在用户空间内核头文件。

Don't include kernel headers in userspace.

由于在C和C ++标准规定,为size_t 定义在&LT; STDDEF.H&GT; (和对于C ++,&LT; cstddef方式&gt; 定义的std ::为size_t

As stated in the C and C++ standards, size_t is defined in <stddef.h> (and for C++, <cstddef> defines std::size_t).

这篇关于C ++包括为size_t的Linux / types.h中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:53