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!

AstroCB
  • 12,337
  • 20
  • 57
  • 73
user3380850
  • 11
  • 1
  • 3
  • 8

1 Answers1

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));
Syntactic Fructose
  • 18,936
  • 23
  • 91
  • 177