【发布时间】:2018-09-29 06:19:29
【问题描述】:
我发现很难在 C++ 中获得这些术语的确切含义。似乎彼此之间有很多重叠(至少 typedef 和命名空间)。你能告诉我为什么这些概念是在 C++ 中发明的吗?我们应该在什么情况下使用这些中的每一个?
另外this 的讨论特别令人困惑。它说'typedef'和'using'是一样的。这让我想知道,如果它们几乎相同,为什么我们会有两个不同的术语?
由于对这些术语的理解不佳,我编写了以下代码并得到如下所示的错误:
文件.hpp
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <fstream>
#include <ostream>
#include <iomanip>
#include <cmath>
class Files {
public:
//@Brief: We create some short forms for long type names
typedef boost::filesystem FS; //! Short form for boost filesystem
// Short form for file name pairs (for example, <200.jpg, 200>)
typedef std::pair<FS::path, int> file_entry;
// Short form for vector of tuples
typedef std::vector<file_entry> vec;
// Short form for iterator of type, boost::filesystem::directory_iterator
typedef FS::directory_iterator dirIter;
};
以下是我收到的 make 错误:
...../include/Files.hpp:10:20: error: ‘filesystem’ in namespace ‘boost’ does not name a type
typedef boost::filesystem FS; //! Short form for boost filesystem
【问题讨论】:
标签: c++ namespaces header-files typedef using