我試圖編譯如下所示的C++代碼,但我得到一個錯誤的說法,'hash'已在此範圍內使用tr1 :: hash聲明;
In file included from src/LM.h:3:0, from src/LM.cpp:1: src/common.h:30:13: error: ‘hash’ is already declared in this scope using tr1::hash;
這是我用來編譯如下文件的命令。
g++ -std=c++11 -Wall src/Foo.cpp
Foo.cpp中
#include "Foo.h"
...
foo.h中
#ifndef FOO_H
#define FOO_H
#include "common.h"
//more code here
#endif
COMMON.H
#ifndef _COMMON_H_
#define _COMMON_H_
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <array>
#include <algorithm>
#include <set>
#include <tr1/unordered_map>
#include <tr1/functional>
namespace std {
using tr1::unordered_map;
using tr1::hash;
} // namespace std
using namespace std;
//more code here
#endif
我想要的源代碼,使用std :: tr1 :: unordered_map和std :: tr1 :: hash而不是std :: unordered_map和std :: hash(A ctually我正在做一些修改分佈式文件,它使用std :: tr1 :: unordered_map和std :: tr1 :: hash)。
我的代碼可能有什麼問題?
UPD: https://github.com/clab/fast_align/blob/master/src/port.h似乎和我一樣。但是,這個編譯沒有任何問題...有任何想法?
出於興趣你爲什麼要使用'std :: tr1 :: hash'而不是'std :: hash'? – sjdowling 2014-10-28 10:23:02
'port.h'編譯是因爲它不包含'',它聲明瞭真正的'std :: hash'。 –
2014-10-28 10:25:38
我修改的源代碼是使用std :: tr1 :: hash,所以我只是跟着它,因爲我不熟悉這些東西。有什麼很大的區別? – hitochan 2014-10-28 10:25:59