Hello all,
I have a strange compiler behaviour with this code:
---- Begin of code snippet ----
class Base
{
public:
static unsigned int ClassId();
};
class Derived
{
public:
static unsigned int ClassId() { return 2; };
};
class Test
{
public:
Test(unsigned int p1) {};
};
int main(int argc, char * argv[])
{
// This works
Test a(Derived::Clas sId());
// This crashes
Test(Derived::C lassId());
return 0;
}
---- End of code snippet ----
The line
Test(Derived::C lassId());
failes to compile with gcc 3.3.5 and Visual Studio 8. With gcc I get
the following error message:
test.cpp: In function `int main(int, char**)':
test.cpp:24: error: prototype for `Test Derived::ClassI d()' does not
match any
in class `Derived'
test.cpp:11: error: candidate is: static unsigned int
Derived::ClassI d()
test.cpp:24: error: `Test Derived::ClassI d()' and `static unsigned int
Derived::ClassI d()' cannot be overloaded
test.cpp:24: error: prototype for `Test Derived::ClassI d()' does not
match any
in class `Derived'
test.cpp:11: error: candidate is: static unsigned int
Derived::ClassI d()
test.cpp:24: error: `Test Derived::ClassI d()' and `static unsigned int
Derived::ClassI d()' cannot be overloaded
test.cpp:24: error: declaration of `Test Derived::ClassI d()' outside of
class
is not definition
So why does it fail with a temporary object in such a way? Should the
compiler not handle this case equivalent to the "non-temporary case"?
Do you have any hints on this behaviour?
Thanks and best regards
Marco