C ++链接器错误:对静态函数的未定义引用 [英] c++ linker error : undefined reference to a static function

查看:87
本文介绍了C ++链接器错误:对静态函数的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A.h文件

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

A.cpp

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

我正在其他文件中调用上述函数.我已经在其中包含.h文件.当我尝试编译时,出现以下错误

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

对A :: func(int&)的未定义引用

undefined reference to A::func(int &)

推荐答案

代码看起来正确.

首先要检查的是您的构建环境已在A.cpp中进行编译和链接.

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

这篇关于C ++链接器错误:对静态函数的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆