English 中文(简体)
错误: 没有匹配的调用对象
原标题:error: no match for call to
  • 时间:2012-05-21 07:37:11
  •  标签:
  • c++
  • arduino

嗨,我正尽力把脑子放在C++和OOP周围。我写了一些代码,在我将其全部放入主循环时,这些代码是有效的。我现在正在整理它,并制作我自己的简单的图书馆和课程。

我的项目有一个8个LED传感器阵列与Arduino 董事会连接。 我正在尝试读取光感应器的状态。 我正在使用QTRSensors 库, 它有一种校准方法, 当我即时给我的班级打电话。

目前我有以下代码。

Header 重

#ifndef SEDIMENTLOGGER_H
#define SEDIMENTLOGGER_H

#include <QTRSensors.h>
#include <Arduino.h>


#define NUM_SENSORS 8


class sedimentSensor
{
 public:
  QTRSensorsRC sensor1;//(unsigned char [8], int&, int&, int&);
  QTRSensorsRC sensor2;//(unsigned char [8], int&, int&, int&);

  sedimentSensor(); //default constructor
  ~sedimentSensor();
  void  calibrateSensors();
  unsigned int *SensorValues1(){return sensorValues1;};
  unsigned int *SensorValues2(){return sensorValues2;};
  int SampleDelay(){return sampleDelay;};
  int EmitterPin1();
  unsigned int Position1(){return position1;};
  void Position1(unsigned int value){position1 = value;};
  unsigned int Position2(){return position2;};
  void Position2(unsigned int value){position2 = value;};

 private:
  // Map pins to LED numbers
  // first LED array
  int led1;
  int led2;
  int led3;
  int led4;
  int led5;
  int led6;
  int led7;
  int led8;
  int emitterPin1;
  //second Array
  int led9;
  int led10;
  int led11;
  int led12;
  int led13;
  int led14;
  int led15;
  int led16;
  int emitterPin2;

  int  timeout; // waits for 2.5 seconds for sensor outputs to go low
  long sampleDelay; // 1 second
  int numSensors;

  unsigned int sensorValues1[];
  unsigned int sensorValues2[];

  unsigned int position1;
  unsigned int position2;
};
#endif

我试图在班级执行

#include "sedimentLogger.h"
#include <Arduino.h>
#include <QTRSensors.h>

sedimentSensor::sedimentSensor() 
{
  //Constructor
  led1 = 24;
  led2 = 26;
  led3 = 28;
  led4 = 30;
  led5 = 32;
  led6 = 34;
  led7 = 36;
  led8 = 38;
  emitterPin1 = 22;
  //second Array
  led9 = 25;
  led10 = 27;
  led11 = 29;
  led12 = 31;
  led13 = 33;
  led14 = 35;
  led15 = 37;
  led16 = 39;
  emitterPin2 = 23;

  timeout = 2500; // waits for 2.5 seconds for sensor outputs to go low
  sampleDelay = 1000; // 1 second

  sensorValues1[NUM_SENSORS];  
  sensorValues2[NUM_SENSORS];
};

sedimentSensor::~sedimentSensor()
{ 
};

int sedimentSensor::EmitterPin1()
{return emitterPin1;};

void sedimentSensor::calibrateSensors()
{
  sensor1((unsigned char[]){led1,led2,led3,led4,led5,led6,led7,led8},numSensors,timeout,emitterPin1);
  sensor2((unsigned char[]) {led9,led10,led11,led12,led13,led14,led15,led16},numSensors,timeout,emitterPin2);


  unsigned int _delay = 500;
  delay(_delay);
  pinMode(13,OUTPUT);
  for(int i = 0; i<400; i++)
    {
      sensor1.calibrate();
      sensor2.calibrate();
    }
  digitalWrite(13,LOW);

  //TODO WRITE MAX AND MIN VALS TO FILE
  Serial.print("Array 1 Min :: ");
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print (sensor1.calibratedMinimumOn[i]);
    Serial.print(   );
  }
  Serial.println();
  Serial.print("Array 2 Min :: ");
  for (int i = 0;i< NUM_SENSORS; i++)
  {
    Serial.print (sensor2.calibratedMinimumOn[i]);
    Serial.print(   );
  }

  Serial.println();
  Serial.print("array 1 Max :: ");
  // print the calibration maximum values measured when emitters were on
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(sensor1.calibratedMaximumOn[i]);
    Serial.print(   );
  }
  Serial.println();
  Serial.print("array 2 Max :: ");
  // print the calibration maximum values measured when emitters were on
  for (int 
  i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(sensor2.calibratedMaximumOn[i]);
    Serial.print(   );
  }

  Serial.println();
  Serial.println();
  delay(_delay); 
};

我的主要功能和回环

#include <QTRSensors.h>
#include <Arduino.h>

#include "sedimentLogger.h"
#include <Wire.h>
#include "/home/marrabld/Programming/Arduino/arduino-1.0/libraries/RTClib/RTClib.h"

sedimentSensor sedLog;//= sedimentSensor();

void setup()
{
  Serial.begin(9600);
  sedLog.calibrateSensors(); 
}

void loop()
{
  sedLog.Position1(sedLog.sensor1.readLine(sedLog.SensorValues1()));
  sedLog.Position2(sedLog.sensor2.readLine(sedLog.SensorValues2()));

  unsigned char i;
  for (i = 0; i < NUM_SENSORS; i++)
    {
      Serial.print(sedLog.SensorValues1()[i] * 10/10001);      
      Serial.print(   );
    }
  Serial.println(sedLog.Position1());
  for (i=0;i < NUM_SENSORS; i++)
    {
      Serial.print(sedLog.SensorValues2()[i]*10/1001);
      Serial.print(   );
    }
  Serial.print("  ");
  Serial.println(sedLog.Position2());
  delay(sedLog.SampleDelay());

  Serial.println(sedLog.SampleDelay());
  Serial.println(sedLog.EmitterPin1()); 
}

我得到以下错误错误

sedimentLogger.cpp: In member function ‘void sedimentSensor::calibrateSensors()’: sedimentLogger.cpp:47:102: error: no match for call to ‘(QTRSensorsRC) (unsigned char [8], int&, int&, int&)’ sedimentLogger.cpp:48:108: error: no match for call to ‘(QTRSensorsRC) (unsigned char [8], int&, int&, int&)’

我尝试了几种不同的变异 比如把感应器的即时反应 放到我的沉积感应器里 和一堆其他的没有运气的东西

我希望得到任何帮助和建议,使这项工作得以进行,我在这里显然也缺少一个概念,因此,任何辅导建议同样会有帮助。

最佳回答

您似乎正在尝试调用 sensor1 sensor2 的构建者, 但是在代码的该点, 他们已经构建了。 请使用它们的 init 函数代替 :

sensor1.init(
    (unsigned char[]){led1,led2,led3,led4,led5,led6,led7,led8},
    numSensors,
    timeout,
    emitterPin1);

sensor2.init(
    (unsigned char[]){led9,led10,led11,led12,led13,led14,led15,led16},
    numSensors,
    timeout,
    emitterPin2);
问题回答

我想47线和48线是以下两个线:

sensor1((unsigned char[]){led1,led2,led3,led4,led5,led6,led7,led8},numSensors,timeout,emitterPin1);
sensor2((unsigned char[]) {led9,led10,led11,led12,led13,led14,led15,led16},numSensors,timeout,emitterPin2);

问题是,您试图将 objects 称为 函数 。 对象需要在构建器中初始化, 如 :

sedimentSensor::sedimentSensor() 
    : led1(24), led2(26), /* other variables needing initialization */
      sensor1(/*arguments*/), sensor2(/*arguments*/)
{
    /* .... */
}

要工作上述内容, 您需要更改类成员变量声明的顺序, 因为排序成员变量初始化的顺序与排序的顺序相同。 换句话说, 您应该将 < code> sensor1 和 < code> sensor2 的宣布设置为 < em > 之后的初始化变量 。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签