gpt4 book ai didi

c++ - 为包含两个类的头文件构建 C++ 文件

转载 作者:行者123 更新时间:2023-11-28 00:31:43 25 4
gpt4 key购买 nike

对象_t.h

class node_t;
typedef node_t * node_tptr;
class list_t;
typedef list_t * list_tptr;

typedef void * TYPE; //void * means we can point to anything with a typecast

class node_t
{
public:
node_t(void); //default constructor
node_t(TYPE newentity); //constructor
void set_next(node_tptr );
node_tptr get_next(void);
TYPE get_entity(void);
private:
node_tptr next; //next link in the list
TYPE entity; //the entity
};

class list_t
{
public:
list_t(void); //default constructor
list_t(const list_tptr); //copy constructor
void insert(TYPE newentity);
TYPE start(void);
TYPE get_next(void);
private:
node_tptr head;
node_tptr tail;
node_tptr current;
};

上面的头文件包含两个不同类的定义。我假设下一步是创建一个名为 object_t.cpp 的 C++ 文件,但是如果在头文件中定义了两个类,那将如何工作?

最佳答案

与 Java 不同,一个 C++ 文件可以包含多个类的实现。只需同时实现这两个 ;-)

关于c++ - 为包含两个类的头文件构建 C++ 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22647557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com