【问题标题】:error: no 'void sim::sendSMS(char*)' member function declared in class 'sim'错误:没有在类“sim”中声明的“void sim::sendSMS(char*)”成员函数
【发布时间】:2016-10-26 15:36:45
【问题描述】:

大家好,我在 Arduino IDE 中编译时遇到此错误

错误:没有在类“sim”中声明的“void sim::sendSMS(char*)”成员函数

void sim::sendSMS(char msg[160])

我的头文件是:

#ifndef sim_h
#define sim_h

#include "Arduino.h"

class sim
{
public:
sim();
void smstextmode();
void testSIM900();
void sendSMS(char _msg[160]);
private:
char _msg[160];
};

#endif

我的 CPP 文件:

#include "Arduino.h"
#include "sim.h"

sim::sim()
{
 _msg= msg;
}

void sim::smstextmode()
{
  Serial1.write("AT+CMGF=1\r\n");
  delay(2000); 
}

void sim::testSIM900()
{
  Serial1.write("AT\r\n");
  delay(1000);
  Serial1.write("AT+CSCS?\r\n");
  delay(1000);
}

void sim::sendSMS(char msg[160])
{
  Serial1.write("AT+CMGS=\"+8295724554\"\r\n");
  delay(1500);
  Serial1.write(msg);
  delay(1000);
  Serial1.write((char) 26)

}

【问题讨论】:

  • 固定 Serial1.write((char)26);还是不行..

标签: c++ class arduino


【解决方案1】:

错误太多了。例如:

sim::sim()
{
   _msg= msg;  // where it should get this msg?
               // Also it's not possible to do a copy of array like this.
}

如果要发送作为参数传递的 msg,为什么需要 _msg?

void sim::sendSMS(char msg[160])

如果你想调用它,你必须使用完全相同的数据类型:

char something[160] = "some text to send";
instance.sendSMS(something);

但你不能直接传递字符串:

instance.sendSMS("some text to send");

因为它的类型是const char *,它不能被类型char[160]处理。

此外,您不计算字符串末尾的终止字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 2018-05-20
    • 1970-01-01
    • 2019-11-25
    相关资源
    最近更新 更多