0

I'm currently designing some code on QT that is built across multiple source. I want to create an array in one source and be able to access it in another source.

Currently in my Header I have class

Array_Class : public QString
{
public:
    static QString Data_Array [2];
};

I don't think I need a constructor as I'm going to "populate" the array before I read it.

currently in my source.cpp I have

Array_Class::Data_Array[0]= "foo";
Array_Class::Data_Array[1]= "bar";

however this gives me the error message undefined reference to "Array_Class::Data_Array". What am I missing? thanks

Jon CO
  • 25
  • 2
  • 10

1 Answers1

3

So far, you have only declared your array:

Array_Class : public QString
{
public:
    static QString Data_Array [2]; // -> only a declaration!
};

In order to use it, you must now define it. To do this, you need to place somewhere in your .cpp:

QString Array_Class::Data_Array [2];
Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49