I've managed to narrow down a problem with my code to this:
class A{
private:
int a;
public:
A(){};
A(int i){a=i;};
const char* str(){
std::stringstream ss;
ss << this << "->" << a;
return ss.str().c_str();
};
};
int main(){
A test[2] = {A(42), A(99)};
printf("%s,%s\n",test[0].str(),test[1].str());
printf("%s,",test[0].str());
printf("%s",test[1].str());
return 0;
}
Which, quite surprisingly, prints this:
0x7ffff5b574a0->42,0x7ffff5b574a0->42
0x7ffff5b574a0->42,0x7ffff5b574a4->99
Why does this happen? Is it printf glitching? Please enlighten me.