.h 文件中的客户端结构与实现结构
Client struct vs. implementation struct in .h file
好吧,这是基本的C ++。 我有一个线性链表类。 我想声明两个结构。 其中一个供客户端使用(即它们将要传递到类中的信息),另一个结构仅供我(实现者)管理链表(这是"节点")。 即:
//this is the one for client use
struct form {
char *name;
int age;
char *address;
//etc.
};
struct node {
char *name; //same as in above but I am sorting the LL by this so I need it out
form *client_form;
node *next;
};
我感到困惑的是将这些放置在哪里。 我相信最好将客户端将使用的结构放在类定义上方,但是放置"节点"结构的最佳位置在哪里。 这应该私下进行吗? 谢谢大家!
节点
结构可以简单地放入您的.cpp文件中。如果您的标头中有一些内容引用了一个节点,例如"struct node *firstNode",那么您必须在标头顶部附近转发声明它,只需说"struct node;"即可。
所以,.h:
struct node;
struct form {
// form fields
};
class MyStuff {
private:
struct node *firstNode;
// more Stuff
};
。.cpp:
struct node {
// node fields
};
MyStuff::MyStuff(struct form const& details) {
// code
}
相关文章:
- 如何使用set实现无序数据结构?
- 如何从实现接口的模板化类实例访问结构
- C++ 在外部使用嵌套结构实现类函数
- C++ 中的 TRIE 数据结构实现
- 数据结构实现
- 为什么type_traits使用结构实现
- 在 c++ 中为结构实现索引器
- C 结构实现派生接口
- 为什么标准库不以无锁的方式为 8 字节以下的结构实现 std::atomic?
- 如何在 C++1x 中为类层次结构实现完全通用的访问者?
- 通过结构实现BST
- 以下 C++ 结构实现之间的区别
- STL如何用非线性数据结构实现反向迭代器去引用
- C++中的数据结构实现
- 编译器特定联合结构实现的标准替代方案
- C++指针返回结构实现:链表
- 为什么不应该以这种方式隐藏结构实现
- 理解数据结构实现代码
- 采用哪种数据结构实现双叶树类型
- c++中访问者模式的层次结构实现