Hi,
On MSVC++, this compiles and runs as expected (even though we really know an acid is never a base):
However, on GCC, I get the error:Code:#include <iostream> using namespace std; struct base { virtual void doit() = 0; }; struct acid : public base { void doit() { cout << "I did it!" << endl; } }; void stuff(base & b) { b.doit(); } int main() { stuff(acid()); return 0; }
Then, of course, making it work is just a matter of:Code:error: invalid initialization of non-const reference of type ‘base&’ from a temporary of type ‘acid’|
And that compiles fine. Why this disparity? Is there any way to make the top code compile in GCC?Code://. . . . . acid a; stuff(a); //. . . .



LinkBack URL
About LinkBacks



