We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is a namespace issue. Both <string> and Student have a function called to_string. The compiler doesn't have enough information to determine which one you're trying to call. When you prefix the function with std::, you're specifying that it's the to_string that exists in the std namespace.
All of the C++ challenges I've seen on this site have using namespace std at the top, which a lot of people consider to be bad practice. That statement allows you to call functions in the std namespace without the prefix std::. This problem shows why that blanket using statement can be troublesome. I recommend not including using namespace std at the top of your files. If you always explicitly qualify std functions with std::, you (and others using your code!) won't run into this issue.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Class
You are viewing a single comment's thread. Return to all comments →
This is a namespace issue. Both
<string>
andStudent
have a function calledto_string
. The compiler doesn't have enough information to determine which one you're trying to call. When you prefix the function withstd::
, you're specifying that it's theto_string
that exists in thestd
namespace.All of the C++ challenges I've seen on this site have
using namespace std
at the top, which a lot of people consider to be bad practice. That statement allows you to call functions in thestd
namespace without the prefixstd::
. This problem shows why that blanketusing
statement can be troublesome. I recommend not includingusing namespace std
at the top of your files. If you always explicitly qualifystd
functions withstd::
, you (and others using your code!) won't run into this issue.