Hello,
I have the following three files
//BEGIN test.h
class foo
{
public:
void print( );
private:
static long int sint;
static char pool[]; // (1)
};
//END test.h
//BEGIN test.cpp
#include <iostream>
#include "test.h"
extern long int number;
long int foo::sint = number; // (3)
char foo::pool[number]; // (2)
void foo::print( )
{
cout << "the number is " << number << endl;
cout << "sint = " << sint << endl;
}
//END test.cpp
//BEGIN testmain.cpp
#include "test.h"
long int number = 14;
int main( )
{
foo t;
t.print( );
}
//END testmain.cpp
If I comment out the lines marked (1) and (2) everything compiles and
runs as expected but with them umcommented my compiler complains thusly:
test.cpp:7: variable-size type declared outside of any function
test.cpp:7: variable-size type declared outside of any function
test.cpp:7: confused by earlier errors, bailing out
It's not clear to me why the extern int is a problem in line (2) but not
in line (3). If anyone could explain the compiler's rationale I would
be most grateful. Thanks.
-exits