Friday, February 19, 2010

Q. Classes with static data members are getting linker errors ("undefined").


A. 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;

1 comment: