Morgen
Ich habe da noch ein paar Tests geschrieben. Vermutlich ist es tatsächlich eine Funktionsdeklaration, bin mir aber nicht ganz sicher.
Gruss, Olli
// main.C
// gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
#include
#include
class test
{
public:
test():mTest(99){ printf( "Test constructor\n" ); }
~test(){ printf( "Test destructor\n" ); }
int getTest(){ return mTest; }
void setTest( int New ){ mTest = New; }
private:
int mTest;
};
// TEST I
int main( int argc, char\* argv[] )
{
test T;
printf( "T.getTest() = %i\n", T.getTest() );
return 0;
}
$ g++ main.C
$ ./a.out
Test constructor
T.getTest() = 99
Test destructor
// TEST II
int main( int argc, char\* argv[] )
{
test T();
printf( "T.getTest() = %i\n", T.getTest() );
return 0;
}
$ g++ main.C
main.C: In function `int main(int, char\*\*)':
main.C:20: request for member `getTest' in `T()', which is of non-aggregate
type `test ()()'
// TEST III
test T()
{
static test \_T ;
\_T.setTest( -1 );
return \_T;
}
int main( int argc, char\* argv[] )
{
test \_T = T();
printf( "\_T.getTest() = %i\n", \_T.getTest() );
return 0;
}
$ g++ main.C
$ ./a.out
Test constructor
\_T.getTest() = -1
Test destructor
Test destructor
// TEST IV
int main( int argc, char\* argv[] )
{
test T()
{
static test \_T;
\_T.setTest( -1 );
return \_T;
}
// test \_T = T();
// printf( "\_T.getTest() = %i\n", \_T.getTest() );
return 0;
}
$ g++ main.C
main.C: In function `int main(int, char\*\*)':
main.C:71: syntax error before `{' token
main.C:73: `\_T' undeclared (first use this function)
main.C:73: (Each undeclared identifier is reported only once for each function
it appears in.)
main.C: At global scope:
main.C:79: syntax error before `return'