当前源代码:
string itoa(int i)
{
std::string s;
std::stringstream out;
out << i;
s = out.str();
return s;
}
class Gregorian
{
public:
string month;
int day;
int year; //negative for BC, positive for AD
// month day, year
Gregorian(string newmonth, int newday, int newyear)
{
month = newmonth;
day = newday;
year = newyear;
}
string twoString()
{
return month + " " + itoa(day) + ", " + itoa(year);
}
};
而在我的主要:
Gregorian date = new Gregorian("June", 5, 1991);
cout << date.twoString();
我收到此错误:
mayan.cc: In function ‘int main(int, char**)’:
mayan.cc:109:51: error: conversion from ‘Gregorian*’ to non-scalar type ‘Gregorian’ requested
有谁知道为什么 int 到字符串的转换在这里失败?我对 C++ 相当陌生,但对 Java 很熟悉,我花了很多时间来寻找这个问题的直接答案,但目前我很困惑。