C++ 如何正确转发带有“declare struct”;使用XXX";?

C++ 如何正确转发带有“declare struct”;使用XXX";?,c++,include,typedef,using,forward-declaration,C++,Include,Typedef,Using,Forward Declaration,我必须使用一个头文件“api.h”,我可以不修改它,但其中所有结构的名称都太长,可读性较差,而且它们的命名样式与我的项目不相似 e、 g.在文件“api.h”中: 因此,我创建了另一个标题“common.h”,以便对它们重新命名 文件“common.hpp”: 但我只想将其包含在实现文件(*.cpp)中,而不是其他头文件中,因为我想加快编译过程。 假设我在“myclass.hpp”中声明了一个类,并在“myclass.cpp”中实现它。 我尝试在“myclass.hpp”中添加一个struct

我必须使用一个头文件“api.h”,我可以修改它,但其中所有结构的名称都太长,可读性较差,而且它们的命名样式与我的项目不相似

e、 g.在文件“api.h”中:

因此,我创建了另一个标题“common.h”,以便对它们重新命名

文件“common.hpp”:

但我只想将其包含在实现文件(*.cpp)中,而不是其他头文件中,因为我想加快编译过程。 假设我在“myclass.hpp”中声明了一个类,并在“myclass.cpp”中实现它。 我尝试在“myclass.hpp”中添加一个struct contradeft的正向声明,如下所示:

#pragma once
namespace MyProject {
struct ContraDef_t;
class MyClass_t {
   MyClass_t( const ContraDef_t * );
   ...
};
};
然后在“myclass.cpp”中:

最后,我可以在“struct”之后加上“error:using typedef name”和“ContraDef_t=struct averyVeryLongNameOfStruct1”来通过编译


我该怎么办?任何帮助或提示都将不胜感激

仅在标题中提出转发声明,并包括该标题:

// common.h
// dont include api.h here !
struct AVERYVERYLONGLONGNAMEOFSTRUCT1;
using ContraDef_t = AVERYVERYLONGLONGNAMEOFSTRUCT1;

// my_class.h
#include "common.h"
struct my_class{ 
    ContraDef_t* c;
};

// my_class.cpp
#include "my_class.h"
#include "api.h"
// ...

仅在标题中提出转发声明,并包括该标题:

// common.h
// dont include api.h here !
struct AVERYVERYLONGLONGNAMEOFSTRUCT1;
using ContraDef_t = AVERYVERYLONGLONGNAMEOFSTRUCT1;

// my_class.h
#include "common.h"
struct my_class{ 
    ContraDef_t* c;
};

// my_class.cpp
#include "my_class.h"
#include "api.h"
// ...

谢谢你的帮助!但我不想在“myclass.hpp”中包含“common.hpp”,因为我想让“myclass.hpp”尽可能简单。还有其他方法吗?@Leon common.h只有前向声明和使用的
,您无法获得比that@Leon你的
common.h
包含了
#api.h
,我知道你不想在
我的class.h
中包含
api.h
。我不会那样做的谢谢你的帮助!但我不想在“myclass.hpp”中包含“common.hpp”,因为我想让“myclass.hpp”尽可能简单。还有其他方法吗?@Leon common.h只有前向声明和使用
,您无法获得比that@Leon你的
common.h
包含了
#api.h
,我知道你不想在
我的class.h
中包含
api.h
。我不这么做
#include "common.hpp"
#include "myclass.hpp"
namespace MyProject {
MyClass_t::MyClass_t( const ContraDef_t * pcd ) {
   ...
};
};
// common.h
// dont include api.h here !
struct AVERYVERYLONGLONGNAMEOFSTRUCT1;
using ContraDef_t = AVERYVERYLONGLONGNAMEOFSTRUCT1;

// my_class.h
#include "common.h"
struct my_class{ 
    ContraDef_t* c;
};

// my_class.cpp
#include "my_class.h"
#include "api.h"
// ...