Relative Content

Tag Archive for c++linkerg++mingwstatic-libraries

How should one include globally defined constants in a C++ library?

I will use a specific, albeit simplified, example to illustrate what I mean. Suppose we are developing a library related to complex numbers. We define two classes, ‘cmplx’ which represents complex numbers, and ‘meta’ which is some class which uses ‘cmplx’ to define its members. We want to provide 3 constant instances of these classes, ‘cmplx0’, ‘cmplxi’, and ‘meta0’. As you’ll see when I present the code, cmplx0 = 0+0*i, cmplxi = 0+i, and meta is just some nonsense I made up to get my point across. The point is each of these variables represents a specific instance of a mathematical object, we want the user to be able to use them pretty much the same way they would use ‘1’ or ‘M_PI’. The problem is I keep getting linking errors when I try to compile.