我已經這樣做了很多次,但 Visual Studio 抱怨這個的原因讓我無法理解。
機械手.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- 有一個卷曲的下劃線,這就是讓我上墻的原因。)
#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
主程式
#include "Manipulator.h"
...
int main()
{
...
Manipulator m;
...
m.proc(opdBMP, fxn, newBMP);
return 0;
}
VS 想要什么才能讓我繼續前進?它告訴我有兩個聯結器錯誤:LNK2019 和 LNK1120(未決議的外部)。(我曾經跟蹤過這些型別的錯誤,但將檔案作為日志丟失了。)
uj5u.com熱心網友回復:
編譯器抱怨是正確的,因為定義應該是
void Manipulator::proc(std::string p, int f, std::string c) {
...
}
您剛剛定義了一個自由函式而不是Manipulator.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372492.html
