我学习 C++ 已经有一段时间了(不是很长),现在我遇到了一个问题:
#ifndef _FILE_A_H
#define _FILE_A_H
template <typename T>
class A {
void func();
/// ... some code here
};
#include "a.cpp"
#endif
我想将 A 类的实现放在文件 'a.cpp'
中。但为此我需要包含 'a.h'
。在这种情况下交叉包含文件是否正常?
我在 'a.cpp'
中有这样的东西(它正在编译但看起来很尴尬):
#ifndef _FILE_A_CPP
#define _FILE_A_CPP
#include "a.h"
template <typename T>
void A<T>::func() {
/// ... some code here
}
/// ... and some code here
#endif
最佳答案
感谢@Magix 的回答。现在我的 a.cpp
更改为 a.tpp
并且看起来像这样:
#include <iostream>
template <typename T>
void A<T>::func() {
/// ... some code here
}
/// ... and some code here
关于C++ 交叉包含——这正常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50212003/