Tag: 数据隐藏

数据隐藏在C ++中

我在C中有一些代码,它以这种方式使用不完整的结构(简化示例): something.h struct something; struct something *new_something(); int work_a(struct something *something); int work_b(struct something *something, const char *str); void free_something(struct something *something); somecode.c int some_function() { struct something *something; int x; something = new_something(); x = work_a(something); free_something(something); return x; } 我在想,我基本上是在做C ++,为什么不尝试用C ++编写。 问题是(我是C ++的新手),我如何在C ++中实现相同的目标? 如果我尝试添加声明一个不完整类的成员函数,我得到 error: incomplete type ‘something’ named in nested […]

隐藏C结构定义

这是我的设置: 在public.h: #ifndef PUBLIC_H_ #define PUBLIC_H_ #include “func.h” /*extern typedef struct _my_private_struct PRIVATE_;*/ typedef struct _my_private_struct PRIVATE_; /* Thanks to larsmans and Simon Richter */ #endif 在struct.h中 #ifndef STRUCT_H_ #define STRUCT_H_ struct _my_private_struct { int i; }; #endif 在func.h中: #ifndef FUNC_H_ #define FUNC_H_ #include “struct.h” /* typedef struct _my_private_struct PRIVATE_; */ extern PRIVATE_ * get_new(int); […]