I have a class Class1 in some header file Class1.hpp
class Class1
{
static std::vector<bool> var1;
func();
}
func()
{
var1.clear();
int t=0;
do
{
var1.push_back(t++);
}while(true); //its some condition
Now inside another function main() in another class in another file, i am assigning var1 to another std::vector like:
std::vector<bool> var2=Class1::var1;
When I am doing this its giving me the error:
undefined reference to Class1::var1
I am not getting what am I doing wrong. Can someone be kind enough to help in rectifying the error?
The error you are getting is a linking error not a compilation error.
The linker tells you that it cannot find definition of
Class1::var1You just declared the vector member but did not define it.
Add:
to only one of your cpp files.
Good Read:
What is the difference between a definition and a declaration?