in the below program i have used static const int init. But it is throwing error
/tmp/ccEkWmkT.o(.text+0x15d): In function check::operation()':check::init’
: undefined reference to
This error is coming only when used with vector. Can someone please help? what is the exact behaviour??
#include<vector>
#include<iostream>
using namespace std;
class check{
static const int init=1;
public:
check(){}
void operation();
};
void check::operation(){
vector<int> dummy;
dummy.push_back(init);
}
int main(){
check ck;
ck.operation();
}
If you pass it by reference it is “used” and you may have to define in the .cpp file so that it gets an address.
If you just use the value of the constant, you might get away with not defining it.