0

I am doing a BigInt implementation and for one of my constructors, I'm required to take in an int value and basically convert it to a string, and then take each character and save it into a node of a linked list.

My struct Digit Node is a doubly linked list with value 'char digit'. My class BigInt has two private member variables head and tail. (which are pointers to DigitNode).

I am getting this error: error: call of overloaded ‘to_string(int&)’ is ambiguous

My file headers:

#include <iosfwd> #include <iostream> #include "bigint.h" using namespace std; 

My constructor:

BigInt::BigInt(int i) // new value equals value of int (also a default ctor) { string num = to_string(i); DigitNode *ptr = new DigitNode; DigitNode *temp; ptr->prev = NULL; this->head = ptr; if (num[0] == '-' || num[0] == '+') ptr->digit = num[0]; else ptr->digit = num[0] - '0'; for (int i = 1; num[i] != '\0'; i++) { ptr->next = new DigitNode; temp = ptr; ptr = ptr->next; ptr->digit = num[i] - '0'; ptr->prev = temp; } ptr->next = NULL; this->tail = ptr; } 

Thanks for your help!

3
  • What compiler are you using? MSVC? Commented Dec 8, 2014 at 3:40
  • Is this your own implementation of to_string or the one included in the standard library? Commented Dec 8, 2014 at 3:42
  • Im using g++. And I'm trying to use the standard library implementation. Commented Dec 8, 2014 at 3:44

1 Answer 1

1

I would have to guess you are using VC 2010, the problem is VC2010 only provides overloads for long, long long, long double, unsigned long. int is not included. You need to use a type compliant instead:

static_cast<long long>(i)

that line would become

string num = to_string(static_cast<long long>(i)); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.