Current source code:
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); } }; And in my main:
Gregorian date = new Gregorian("June", 5, 1991); cout << date.twoString(); I'm getting this error:
mayan.cc: In function ‘int main(int, char**)’: mayan.cc:109:51: error: conversion from ‘Gregorian*’ to non-scalar type ‘Gregorian’ requested Does anyone know why int to string conversion is failing in here? I'm fairly new to C++ but am familiar with Java, I've spent a good deal of time looking for a straightforward answer to this problem but am currently stumped.
std::string s;initoaand justreturn out.str();. The return string will be constructed before the stringstream is destroyed. Reasonable compilers will likely produce the exact same code in both cases, but the extra temporary tends to suggest to people looking at your code that you don't understand or trust the C++ scoping rules.toString()?