【发布时间】:2014-12-08 03:37:28
【问题描述】:
我正在做一个 BigInt 实现,对于我的一个构造函数,我需要接受一个 int 值并将其基本上转换为一个字符串,然后将每个字符保存到链表的一个节点中。
我的 struct Digit Node 是一个双向链表,其值为 'char digit'。我的 BigInt 类有两个私有成员变量 head 和 tail。 (指向 DigitNode 的指针)。
我收到此错误:错误:调用重载的“to_string(int&)”不明确
我的文件头:
#include <iosfwd>
#include <iostream>
#include "bigint.h"
using namespace std;
我的构造函数:
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;
}
感谢您的帮助!
【问题讨论】:
-
你用的是什么编译器? MSVC?
-
这是您自己实现的
to_string还是标准库中包含的那个? -
我正在使用 g++。我正在尝试使用标准库实现。