G
Guest
I have Visual Studio 7.1 and I wrote the following C++ program
#include <iostream
using namespace std
class ID
private
static unsigned long s_id
public
static unsigned long Next(
return (++s_id)
}
unsigned long ID::s_id = 0
class A
public
static const int id = ID::Next()
}
class B
public
static const int id = ID::Next()
}
int main(int argc, char* argv[]
cout << "A.id=" << A::id << endl
cout << "B.id=" << B::id << endl
return 0
I believe this is incorrect C++ and shouldn't compile. However, I get zero compiler errors and a program output of
A.id=
B.id=
When I compiled this on GCC 2.95.3 (March 2001) I get the following errors at the two id=ID::Next() lines
"field initializer is not constant
Shouldn't VC give me the same errors? Why is it compiling to produce '0'
Thanks
Jeff
#include <iostream
using namespace std
class ID
private
static unsigned long s_id
public
static unsigned long Next(
return (++s_id)
}
unsigned long ID::s_id = 0
class A
public
static const int id = ID::Next()
}
class B
public
static const int id = ID::Next()
}
int main(int argc, char* argv[]
cout << "A.id=" << A::id << endl
cout << "B.id=" << B::id << endl
return 0
I believe this is incorrect C++ and shouldn't compile. However, I get zero compiler errors and a program output of
A.id=
B.id=
When I compiled this on GCC 2.95.3 (March 2001) I get the following errors at the two id=ID::Next() lines
"field initializer is not constant
Shouldn't VC give me the same errors? Why is it compiling to produce '0'
Thanks
Jeff