Static data member giving undefined reference errors.
Posted: Sat Sep 13, 2014 10:05 pm
I am using the constructor/destructor code from Trion. Constructors are working, however when I attempt to use a static data member, it is giving me an undefined reference error. I don't think it's covered in the C++ wiki page. Note that I use constexpr so that I can use the array in an enum class and initialize it inside the class. However, the error persists if I don't use constexpr and initialize the elements manually.
Terminal.hpp
Terminal.cpp
Is there something extra that I have to do for static data members?
Notes:
Terminal.hpp
Code: Select all
class Terminal
{
constexpr static uint32_t col_map[16] = {
0x000000, 0x0000AA, 0x00AA00, 0x00AAAA,
0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA,
0x555555, 0x5555FF, 0x55FF55, 0x55FFFF,
0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF
};
enum class Color : uint32_t
{
Black = col_map[0],
White = col_map[15]
};
// ...
};
static Terminal terminal;
Code: Select all
void Terminal::drawcolormap()
{
// ...
putpixel(n + i * 50, m + j * 40, col_map[col]);
// ...
Notes:
- I have tried to reproduce the undefined reference error in a test program using a regular compiler unsuccessfully.
- Don't pay attention to "static Terminal terminal;" it seems unrelated to the error.