[英]Ways of eliminating including C++ class header files when they was used in the client's function declaration head file
Suppose I have the following header file: 假设我有以下头文件:
abc_header.h abc_header.h
class Abc
{
public:
int a;
int b;
int c;
};
typedef std::vector<Abc> AbcArray;
Then if I want to use this class, I can declare the function that use this class in this way without including the abc_header.h header file: 然后,如果要使用此类,则可以以这种方式声明使用此类的函数,而无需包括abc_header.h头文件:
client1.h client1.h
class Abc;
void useAbc(Abc &pObj);
Only in the implementation part, the head file will be included. 仅在实现部分中将包含头文件。 Then I have another function that will use AbcArray
class, and in this case it seems that I have to include the abc_header.h header in the function declaration part as the following shows: 然后,我有了另一个将使用AbcArray
类的函数,在这种情况下,似乎必须在函数声明部分中包含abc_header.h标头,如下所示:
client2.h client2.h
#include "abc_header.h"
void useAbcArray(AbcArray &array);
Any possibility of without including the header file? 有没有不包括头文件的可能性吗? Thanks. 谢谢。
Just have forward declaration Abc and (!) AbcArray in another header abc_forward_header.h: 只需在另一个标头abc_forward_header.h中具有前向声明Abc和(!)AbcArray:
class Abc;
typedef std::vector<Abc> AbcArray;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.