Skip to content

C++ quiz from the past

One of my friends once encountered a C++ compilation issue.
A program is given:

#include <iostream>
#include <sstream>
using namespace std;

#define SFORMAT(e) ((dynamic_cast<const ostringstream&>(ostringstream() << e)).str())

int main(int argc, char* argv[])
cout << SFORMAT("2 x " << " 2 = " << 2*2);
return 0;

No one asks you what it will print, unless you’re a god.

Question is: why is the first const char* printed as a pointer, instead of what we need?
Two years ago, I couldn’t tell.
Some guru from Apple answered this in a newsgroup.

Here, take another, simpler C++ quiz about member pointers.

Post a Comment

Your email is never published nor shared.