1.

Classes With Static Data Members Are Getting Linker Errors ("undefined").?

Answer»

This code is BUILT into Turbo C++ 1.0 but not in version 3.0. In the 1.0 compiler, static members without definitions were given a default value of 0. This default definition will no longer be made in the compiler. The programmer must now give an explicit definition for each static member.

Here is a quick example: 

class A 

static int i; 

}; 

A linker ERROR saying that A::i is not defined will RESULT UNLESS the SOURCE also contains a line such as: 

int A::i = 1;

This code is built into Turbo C++ 1.0 but not in version 3.0. In the 1.0 compiler, static members without definitions were given a default value of 0. This default definition will no longer be made in the compiler. The programmer must now give an explicit definition for each static member.

Here is a quick example: 

class A 

static int i; 

}; 

A linker error saying that A::i is not defined will result unless the source also contains a line such as: 

int A::i = 1;



Discussion

No Comment Found