c++ linker error : undefined reference to a static

2020-05-01 08:29发布

问题:

A.h file

class A{
      public:
      static int* func (int &b);
}

A.cpp

int* A::func(int &b){
   //some definition here
}

I am calling the above function in some other file. I have included the .h file in that. When I try to compile I get the following error

undefined reference to A::func(int &)

回答1:

The code looks right.

The first thing to check is that your build environment compiled and linked in A.cpp.