[英]Compiler/linker complaining about function definition not found in C++
I've done this so many times, yet the reason why Visual Studio is complaining about this escapes me.我已经这样做了很多次,但 Visual Studio 抱怨这个的原因让我无法理解。
Manipulator.cpp:操纵器.cpp:
#include "Manipulator.h"
Manipulator::Manipulator() {}
Manipulator::~Manipulator() {}
void proc(std::string p, int f, std::string c)
{
// switch-case p to c based on f:
return;
}
Manipulator.h: (void -proc- has a curly underscore, and that's what's driving me up the wall.) Manipulator.h:(void -proc- 有一个卷曲的下划线,这就是让我陷入困境的原因。)
#ifndef MANIPULATOR_H
#define MANIPULATOR_H
#include <string>
class Manipulator
{
private:
protected:
public:
Manipulator() ;
~Manipulator() ;
void proc(std::string, int, std::string);
// function definition for 'proc' not found.
};
#endif MANIPULATOR_H
main.cpp主文件
#include "Manipulator.h"
...
int main()
{
...
Manipulator m;
...
m.proc(opdBMP, fxn, newBMP);
return 0;
}
What is it that VS wants so that I can get a move on? VS 想要什么让我继续前进? It is telling me that there are two linker errors: LNK2019 and LNK1120 (unresolved external).
它告诉我有两个 linker 错误:LNK2019 和 LNK1120(未解决的外部)。 (I used to keep track of these kinds of errors but lost the file as a log with these.)
(我曾经跟踪这些类型的错误,但将文件作为日志丢失了。)
The compiler is correct in complaining, because the definition should be编译器在抱怨是正确的,因为定义应该是
void Manipulator::proc(std::string p, int f, std::string c) {
...
}
You just defined a free function instead of a member of Manipulator
.您刚刚定义了一个免费的 function 而不是
Manipulator
的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.