调用其他文件中类的方法,不想包含其头文件
test.h
#include <iostream.h>
class A
{
public:
test(){cout<<"test"<<endl;}
};
testcmd.cpp
#include "stdafx.h"
class A;
int main()
{
A* a= new A();
a->test();
return 0;
}
最近看到项目中有个头文件有2000多行代码,30~40个类的声明,都包含该文件的话,会让编译变的很慢,也不想放到预编译头stdafx.h中。
下面是一个具体实例
我不想包含test.h头文件,而使用class A,调用a的成员方法test(),请问该怎么办。
[解决办法]
也可以用宏定义,只包含CLASS A:
test.h
#include <iostream.h>
#ifndef __ONLY_USE_CALSS_A__
...
#endif
class A
{
public:
test(){cout<<"test"<<endl;}
};
#ifndef __ONLY_USE_CALSS_A__
...
#endif
testcmd.cpp
#include "stdafx.h"
#define __ONLY_USE_CALSS_A__
#include "test.h"
class A;
int main()
{
A* a= new A();
a->test();
return 0;
}