Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9232711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:22:44+00:00 2026-06-18T06:22:44+00:00

I have two files: error.h and error.cpp. Compiling with g++ -std=c++0x gives me an

  • 0

I have two files: error.h and error.cpp. Compiling with

g++ -std=c++0x

gives me an error:

error.cpp:9:33:**call of overloaded "to_string(char*&)" is ambiguous**

How can i fix this problem?

error.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

error.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 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:22:45+00:00Added an answer on June 18, 2026 at 6:22 am

    to_string() is used to convert something which is not a string (e.g. a long, an int, etc.) into a string. You have a char*, which is a C string, and what you want to do is to create a string object out of it, not convert it.

    Your compiler complains about ambiguity because it cannot find a version of to_string() for the type you are passing to it (char*), which makes sense, considering the purpose of that function.

    If you declared your parameter string const& rather than string& in the corresponding overload of setMsg() (and in the constructor of Error as well), you could directly invoke it by passing C strings: a temporary of type string would be created automatically and bound to the argument of setMsg().

    This way you would even get rid of the specific overload of setMsg() for C strings, which in fact does nothing but forwarding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files 1 - index.php 2 - main.php index.php call to main.php
I have two files called file_utils.h and file_utils.cpp which contain some methods and variables
I have two C++ files, say file1.cpp and file2.cpp as //file1.cpp #include<cstdio> void fun(int
I have two source files, one named main.cpp (where the namespace M is defined)
I have two files: osm.h and osm.cpp I tried to create static lib from
I have two files once is named as test.cpp and another as ani.cpp. test.cpp
I have two files: hello.h and hello.cpp hello.h #ifndef __HELLO_H__ #define __HELLO_H__ using namespace
I have two files: // event_test_delete.cpp #include <event.h> int main() { event_base* ev; ev
I have a problem with generics in c++.I have two Matrix.h and Matrix.cpp files.Here
I have two files: File1.cpp File2.cpp File1 is my main class which has the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.