C++ C++;:&引用;对WeightCalc::GetHearter(int)的未定义引用;
我有以下详细的课程:(我用Arduino语言编程,基本上是C++) 重量测试仪\u main.cpp:C++ C++;:&引用;对WeightCalc::GetHearter(int)的未定义引用;,c++,class,c++11,arduino,C++,Class,C++11,Arduino,我有以下详细的课程:(我用Arduino语言编程,基本上是C++) 重量测试仪\u main.cpp: #include "Weight_Tester_main.h" #include "weightcalc.h" WeightCalc weight; int PotPin = A0; int PotVal = 0; int ALED = 12; int BLED = 13; void setup() { Serial.begin(9600); pinMode(ALED
#include "Weight_Tester_main.h"
#include "weightcalc.h"
WeightCalc weight;
int PotPin = A0;
int PotVal = 0;
int ALED = 12;
int BLED = 13;
void setup() {
Serial.begin(9600);
pinMode(ALED, OUTPUT);
pinMode(BLED, OUTPUT);
pinMode(btnPin, INPUT);
Serial.println("Setup complete. Both LEDs have been configured as outputs. The button has been set.");
delay(500);
}
void loop() {
PotVal = analogRead(PotPin);
Serial.println(weight.getHeavier(PotVal));
}
重量测试仪主h:
//-------------------------------------------------------------------
#ifndef __weight_tester_main_H__
#define __weight_tester_main_H__
//-------------------------------------------------------------------
#include <arduino.h>
//-------------------------------------------------------------------
//-------------------------------------------------------------------
void setup();
void loop();
//-------------------------------------------------------------------
//===================================================================
// -> DO NOT WRITE ANYTHING BETWEEN HERE...
// This section is reserved for automated code generation
// This process tries to detect all user-created
// functions in main_sketch.cpp, and inject their
// declarations into this file.
// If you do not want to use this automated process,
// simply delete the lines below, with "&MM_DECLA" text
//===================================================================
//---- DO NOT DELETE THIS LINE -- @MM_DECLA_BEG@---------------------
void loop();
void setup();
//---- DO NOT DELETE THIS LINE -- @MM_DECLA_END@---------------------
// -> ...AND HERE. This space is reserved for automated code generation!
//===================================================================
//-------------------------------------------------------------------
#endif
//-------------------------------------------------------------------
//-------------------------------------------------------------------
#ifndef重量测试仪主__
#定义重量测试仪主__
//-------------------------------------------------------------------
#包括
//-------------------------------------------------------------------
//-------------------------------------------------------------------
无效设置();
void loop();
//-------------------------------------------------------------------
//===================================================================
//->请勿在此处之间写入任何内容。。。
//此部分保留用于自动代码生成
//此过程尝试检测所有用户创建的
//函数,并将其
//将声明保存到此文件中。
//如果您不想使用此自动化流程,
//只需使用“&MM_DECLA”文本删除下面的行即可
//===================================================================
//----请勿删除此行--@MM_DECLA_BEG@---------------------
void loop();
无效设置();
//----请勿删除此行--@MM_DECLA_END@---------------------
//->…还有这里。此空间用于自动生成代码!
//===================================================================
//-------------------------------------------------------------------
#恩迪夫
//-------------------------------------------------------------------
weightcalc.cpp:
#include "weightcalc.h"
int getHeavier (int Value) {
digitalWrite(13,LOW);
digitalWrite(12,LOW);
// Ready to go boolean
boolean readytogo = true;
// Here, we know Value is the Pot's Value which our main program is going to pass to us
// So we check it for a certain value
Value = 512 ? Serial.println("Perfect!") : Serial.println("Not exact, but who cares as long as its between our range.");
if (Value > 500 && Value < 530) {
Serial.println(" We are good to go!");
readytogo = true;
delay(2000);
Serial.println("Please put the objects in each of the containers.");
delay(20000);
}
else {
readytogo = false;
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
}
if (!readytogo) {
Serial.println("Aborting......");
return -1;
}
else {
;
}
int newValue = analogRead(A0);
if (newValue < 500) {
Serial.println ("A is heavier.");
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
return 0;
}
else if (newValue > 530) {
Serial.println("B is heavier.");
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
return 1;
}
else {
Serial.println("They are both about the same weight.");
return 2;
}
}
#包括“weightcalc.h”
int(int值){
数字写入(13,低);
数字写入(12,低);
//准备好了吗
布尔readytogo=true;
//在这里,我们知道Value是Pot的值,我们的主程序将传递给我们
//所以我们检查它的某个值
Value=512?Serial.println(“完美!”):Serial.println(“不精确,但谁在乎,只要它在我们的范围内。”);
如果(值>500&&值<530){
Serial.println(“我们可以走了!”);
readytogo=true;
延迟(2000年);
println(“请将对象放在每个容器中。”);
延迟(20 000);
}
否则{
readytogo=false;
数字写入(10,高);
数字写入(11,高);
}
如果(!readytogo){
Serial.println(“中止……”);
返回-1;
}
否则{
;
}
int newValue=analogRead(A0);
如果(新值<500){
Serial.println(“A更重”);
数字写入(13,低);
数字写入(12,高);
返回0;
}
否则如果(新值>530){
Serial.println(“B更重”);
数字写入(13,高);
数字写入(12,低);
返回1;
}
否则{
println(“它们的重量差不多。”);
返回2;
}
}
权重计算h:
//-------------------------------------------------------------------
#ifndef __weightcalc_H__
#define __weightcalc_H__
//-------------------------------------------------------------------
#include <arduino.h>
//-------------------------------------------------------------------
//-------------------------------------------------------------------
class WeightCalc{
public:
int getHeavier(int Value);
};
//-------------------------------------------------------------------
//===================================================================
// -> DO NOT WRITE ANYTHING BETWEEN HERE...
// This section is reserved for automated code generation
// This process tries to detect all user-created
// functions in main_sketch.cpp, and inject their
// declarations into this file.
// If you do not want to use this automated process,
// simply delete the lines below, with "&MM_DECLA" text
//===================================================================
//---- DO NOT DELETE THIS LINE -- @MM_DECLA_BEG@---------------------
//---- DO NOT DELETE THIS LINE -- @MM_DECLA_END@---------------------
// -> ...AND HERE. This space is reserved for automated code generation!
//===================================================================
//-------------------------------------------------------------------
#endif
//-------------------------------------------------------------------
//-------------------------------------------------------------------
#ifndef uu重量计算__
#定义权重计算__
//-------------------------------------------------------------------
#包括
//-------------------------------------------------------------------
//-------------------------------------------------------------------
类权重计算{
公众:
int(int值);
};
//-------------------------------------------------------------------
//===================================================================
//->请勿在此处之间写入任何内容。。。
//此部分保留用于自动代码生成
//此过程尝试检测所有用户创建的
//函数,并将其
//将声明保存到此文件中。
//如果您不想使用此自动化流程,
//只需使用“&MM_DECLA”文本删除下面的行即可
//===================================================================
//----请勿删除此行--@MM_DECLA_BEG@---------------------
//----请勿删除此行--@MM_DECLA_END@---------------------
//->…还有这里。此空间用于自动生成代码!
//===================================================================
//-------------------------------------------------------------------
#恩迪夫
//-------------------------------------------------------------------
我得到了你在标题中看到的错误。我正在使用MariaMole IDE。很抱歉,这主要是代码,但我想展示所有内容,以便您能够提供帮助 您不应该在WeightCalc.cpp的顶部指定WeightCalc::getHearter(int)而不是getHearter(int)吗?看起来您没有从类中实现声明的函数。该名称是全局定义的。您正在使用。您的问题将在链接副本中得到解答(一个常见错误是忘记限定名称),谢谢!我不太懂C++,所以我会记住这个的!