Question

J'essaie d'obtenir le code suivant de nmdepend compiler

const std::string Bfd::packageName(const fs::path& path, int packageLevel)
{
  fs::path::iterator p = path.end();
  --p;

  for(int i = 0; i < packageLevel; ++i)
      --p;

  return *p;
}

Cependant, il génère l'erreur du compilateur suivant

/Users/nick/Software/nmdepend/src/Bfd.cpp: In static member function ‘static const std::string Bfd::packageName(const boost::filesystem3::path&, int)’:
/Users/nick/Software/nmdepend/src/Bfd.cpp:27: error: conversion from ‘const boost::filesystem3::path’ to non-scalar type ‘const std::string’ requested

Comment modifier ce code afin qu'une chaîne soit renvoyée mais la manipulation qui est tentée à l'aide d'un itérateur est maintenue?

Était-ce utile?

La solution

path n'est pas implicitement convertible en chaîne. Cela devrait cependant fonctionner:

return p->string();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top