One of my friends recently showed me the following sample of code:He said that the output was "abc", but I got the memory address instead. He was running on a Linux machine, so we're using different compilers. I'm using .Net. I'm sure that one behavior or the other is considered "correct". I tried looking through the standard, but I got bogged down in it pretty quickly. Which behavior is "correct"?Code:#include<iostream> using std::cout; using std::endl; class MyClass { public: MyClass(); char buffer[4]; operator char *(); }; MyClass::MyClass() { buffer[0] = 'a'; buffer[1] = 'b'; buffer[2] = 'c'; buffer[3] = '\0'; } MyClass::operator char*() { return buffer; } int main() { MyClass test; cout << test << endl; return 0; }



LinkBack URL
About LinkBacks



)