Вопрос

I'm attempting to get the following code from nmdepend to compile

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;
}

However it is generating the following compiler error

/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

How should this code be modified so that a string is returned yet the manipulation that is being attempted by using an iterator is maintained?

Это было полезно?

Решение

path is not implicitly convertible to string. This should work though:

return p->string();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top