我在問C++項目中廣泛使用的最佳實踐。我需要在項目中擁有自己的類型。它是一對typedef的集合。命名空間與頭文件
是否包含包含C++類型良好實踐的頭文件,還是使用命名空間更好。如果是這樣,爲什麼?這兩種方式有什麼優點和缺點?
現在它看起來是這樣的:
types.h中:
#ifndef TYPES_H
#define TYPES_H
#include <list>
// forward declaration
class Class;
typedef int TInt;
// ...
typedef std::list<Class> class_list;
#endif
class.h:
#ifndef CLASS_H
#define CLASS_H
#include "types.h"
class Class
{
public:
// ...
TInt getMethod();
private:
// ...
};
它是如何將看起來像命名空間?