Hi everybody,
I think this question will be kind of stupid for you ... but I am fighting with since yesterday evening.
I have a class Test defined as such in the hpp file (Test.hpp)
#include <iostream>
#include <vector>
using namespace std;
class Test {
public:
Test();
static const int SOMEVALUE = 1200;
void testFunction();
private:
vector <int> vectorOfValues;
};
The file Test.cpp is as such :
#include <vector>
#include <iostream>
#include "Test.hpp"
using namespace std;
Test::Test() {
}
void Test::testFunction() {
vectorOfValues.push_back(SOMEVALUE);
}
The main file is very simple :
#include <iostream>
#include "Test.hpp"
using namespace std;
int main() {
Test t;
t.testFunction();
}
When trying to compile, the compiler returns the following error :
/tmp/ccA63Hmn.o: In function `Test::testFunction()':
Test.cpp:(.text+0x45): undefined reference to `Test::SOMEVALUE'
collect2: ld returned 1 exit status
However, if modify the testFunction function (see below) I don't have this problem, meaning that there is no access problem to my SOMEVALUE constant.
void Test::testFunction() {
cout << SOMEVALUE << endl;
}
What do you think of it?
I thank you a lot for your help!