2012-02-20 13 views
2

私はエージェントモデリングプロジェクトに取り組んでおり、そのためにrepastを使うことに決めました。 私は以前にライブラリの束をあらかじめインストールしておき、Repastソースをダウンロードしてプロジェクトに組み込もうとしました。しかし、突然私が理解できないエラーを得る。C++コンパイルエラー(REPASTライブラリ)

error: no match for ‘operator+’ in ‘std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*) [with _CharT = char, _Traits = std::char_traits, _Alloc = std::allocator](((const char*)"_")) + boost::filesystem3::path::filename() const()’

CODE:

NCDataSet::NCDataSet(std::string file, const Schedule& schedule) : 
file_(file), schedule_(&schedule), start(0), open(true) 
{ 
    rank = RepastProcess::instance()->rank(); 
    if (rank == 0) { 
     fs::path filepath(file); 
     if (!fs::exists(filepath.parent_path())) { 
      fs::create_directories(filepath.parent_path()); 
     } else if (fs::exists(filepath)) { 
      string ts; 
      repast::timestamp2(ts); 
      fs::path to(filepath.parent_path()/(ts + "_" + filepath.filename())); 
     fs::rename(filepath, to); 
    } 
} 
} 
ERROR LINE: fs::path to(filepath.parent_path()/(ts + "_" + filepath.filename())); 

感謝!

+0

唯一のエラーですか?そうでない場合、完全なコンパイラ出力を投稿できますか? – hmjd

答えて

1

エラーは、operator+と一致しないことを示します。つまり、2つの無効なタイプを追加しようとしています。

path::filenameはstd :: stringを返しません。

class path { 
    // ... 
    path filename() const; 
    // ... 
}; 

中置演算子は、演算の左側の型を保持すると考えるのが妥当です。この場合、std::stringはブーストまたはfilesystem::pathについて何も知らない。

だからあなたはおそらくこのような何かに問題のある行を変更する必要があります。私はインライン操作の束がエラーを起こしているかすぐに分からないときに見つける

fs::path to(filepath.parent_path()/(ts + "_" + filepath.filename().string())); 

を、それがに良い練習ですすべてを自分の行に分けてください。この場合、コードはあなたの意図に対して少し明確になります。

std::string old_filename(filepath.filename().string()); 
std::string new_filename = ts +"_"+ old_filename; 
fs::path to(filepath.parent_path()/new_filename); 
関連する問題