Hi,
On MSVC++, this compiles and runs as expected (even though we really know an acid is never a base):
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;
}
However, on GCC, I get the error:
Code:
error: invalid initialization of non-const reference of type ‘base&’ from a temporary of type ‘acid’|
Then, of course, making it work is just a matter of:
Code:
//. . . . .
acid a;
stuff(a);
//. . . .
And that compiles fine. Why this disparity? Is there any way to make the top code compile in GCC?