C++ : "undefined reference to WeightCalc::getHeavier(int)"

标签 c++ class c++11 arduino

<分区>

我在下面详细介绍了以下类(class):(我正在使用基本上是 C++ 的 Arduino 语言进行编程)

Weight_Tester_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, 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));
}

Weight_Tester_main.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
//-------------------------------------------------------------------

重量计算.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;
}

}

权重计算.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
//-------------------------------------------------------------------

我得到了您在标题中看到的错误。我正在使用 MariaMole IDE。抱歉,这主要是代码,但我想展示所有内容以便您提供帮助。

最佳答案

难道你不应该在 weightCalc.cpp 的顶部指定 WeightCalc::getHeavier(int) 而不是 getHeavier(int) 吗?看起来你没有实现类中声明的函数。那个是全局定义的。

关于C++ : "undefined reference to WeightCalc::getHeavier(int)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24066362/

相关文章:

java - 你认为 class string 实现的接口(interface)在 Java 中可比吗

c++ - 如果相似元素已存在,则从 std::list 中移除元素

c++ - 如何将函数作为参数传递

c++ - 使用 "ldaps"绑定(bind)到 ldap 服务器

c++ - 如何在 block 中途重命名变量?

actionscript-3 - 是否可以从其他包访问包外的类?

c++ - std::is_signed<T> 和 std::numeric_limits<T>::is_signed 之间的区别?

python - 比较和交换python中的指令

java - java中方法的原型(prototype)

c++ - 使用自动循环时代码崩溃