Wednesday, October 30, 2013

C++ Static Variables

Other than the usual differences in scope, there are some unique aspects of the syntax that will stump a developer from a Java background.

While instance variables only require declaration in the header file, a static variable in C++ needs to be declared twice, once in the header file and another in the CPP file. Otherwise you'll get a linker error.

See here for example: http://stackoverflow.com/questions/9282354/static-variable-link-error

No comments:

Post a Comment