我有两个文件:error.h 和 error.cpp。编译
g++ -std=c++0x
给我一个错误:
error.cpp:9:33:**call of overloaded "to_string(char*&)" is ambiguous**
我该如何解决这个问题?
错误.h:
1 #ifndef ERROR_H_GUARD
2 #define ERROR_H_GUARD
4 #include <string>
6 class Error {
7 public:
8 Error(int pos, std::string& msg);
10 Error(int pos, char* msg);
12 const char* what() throw();
14 private:
15 std::string msg;
17 void setMsg(int pos, std::string& msg);
18 };
19
20 #endif
错误.cpp:
2 #include "error.h"
4 Error::Error(int pos, std::string& msg){
5 setMsg(pos, msg);
6 }
8 Error::Error(int pos, char* msg) {
9 setMsg(pos, std::to_string(msg));
10 }
12 const char* Error::what() throw() {
13 return msg.c_str();
14 }
16 void Error::setMsg(int pos, std::string& msg){
17 this->msg = std::to_string(pos) + msg + std::string("\n") + std::string(pos - 1, ' ') + std::string("^");
18 }