Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么调用在另一个文件中声明和定义的成员函数会导致链接错误?_C++_Linker_Linker Errors_Lnk2019 - Fatal编程技术网

C++ 为什么调用在另一个文件中声明和定义的成员函数会导致链接错误?

C++ 为什么调用在另一个文件中声明和定义的成员函数会导致链接错误?,c++,linker,linker-errors,lnk2019,C++,Linker,Linker Errors,Lnk2019,我正在尝试调用公共成员函数: // main.cpp #include "AH.h" int somefunc() { //... // it - object of class A it.set_mean(angle, mean); //... } 在.h.中声明的 // AH.h class A { //... public: inline void set_mean(const int angle, const double mean_value); //... } 并在

我正在尝试调用公共成员函数:

// main.cpp
#include "AH.h"
int somefunc()
{
//...
// it - object of class A
    it.set_mean(angle, mean);
//...
}
在.h.中声明的

// AH.h
class A
{
//...
public:
   inline void set_mean(const int angle, const double mean_value);
//...
}
并在.cpp文件中定义:

// A.cpp
#include "AH.h"
inline void A::set_mean(const int angle, const double mean_value)
{
    mean[angle] = mean_value;
}
以及接收LNK错误:

error LNK2019: unresolved external symbol "public: void __cdecl A::set_mean(int,double)" (?set_mean@A@@QEAAXHN@Z) referenced in function "int __cdecl somefunc(class std::vector<class A,class std::allocator<class A> > &)" (?somefunc@@YAHAEAV?$vector@VA@@V?$allocator@VA@@@std@@@std@@@Z)

为什么会发生这种情况?

如果编译器看不到实现,它如何内联函数?你确定你正在链接a.o吗?你是如何编译代码的?@David,是的,没错!谢谢在.h文件中添加了定义,现在可以使用了。