Arduino no matching function for call to - c++

I have created program for my arduino uno, but I cannot compile it.
Program based on IRemote IRecord example, and SD example.
CODE:
void sendCode(int repeat) {
strcodeValue = String(codeValue);
char filename[strcodeValue.length()+1];
strcodeValue.toCharArray(filename, sizeof(filename));
if (SD.exists(filename)) {
File myFile = SD.open(filename);
if (myFile) {
while (myFile.available(filename)) {
codeValue = myFile.read();
}
myFile.close();
}
}
...
}
ERRORS:
IRrecord.ino: In function 'void sendCode(int)':
IRrecord.ino:130:37: error: no matching function for call to 'File::available(char [(((sizetype)<anonymous>) + 1)])'
IRrecord.ino:130:37: note: candidate is:
In file included from IRrecord.ino:18:0:
C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:38:15: note: virtual int File::available()
virtual int available();
^
C:\Program Files (x86)\Arduino\libraries\SD\src/SD.h:38:15: note: candidate expects 0 arguments, 1 provided
Error compiling.
File name will be read from IR Sensor.
Can anyone help me?

It surely looks like
while (myFile.available(filename)) {
should read
while (myFile.available()) {

Related

How to use a library within a library (Arduino)

My C++ skills are rather amateurish, but I’m trying to write a library for a differential drive robotic platform. The library in question needs to utilise a PID library and a rotary encoder library.
I’d like to utilise “levels of abstraction” to do this, rather than just having a massive “sketch” as it makes things a lot easier to read, and to be honest, is the point of object orientated programming. I.e i can write a class to control the a dc motor and just use multiple instances for each side. (I apologise if I’ve got the terminology wrong).
Essentially I’m having trouble utilising the third party libraries within my library.
If i was to write a simple sketch that used the two third party libraries, it would look like this (paraphrasing) -
#include <Arduino.h>
#include <RotaryEncoder.h>
#include <PID_v1.h>
#include <L298N.h>
char A_IN1 = 8;
char A_IN2 = 9;
char A_EN = 17;
char PIN_IN1 = 4;
char PIN_IN2 = 5;
double Setpoint, Output;
double Input = 0;
double Kp=1.3, Ki=15, Kd=0.01;
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
void checkPosition(){
//some code that increments the encoder value
}
void setup(){
attachInterrupt(digitalPinToInterrupt(PIN_IN1), checkPosition, CHANGE);
pinMode(PIN_IN1, INPUT);
attachInterrupt(digitalPinToInterrupt(PIN_IN2), checkPosition, CHANGE);
pinMode(PIN_IN2, INPUT);
Setpoint = 0;
myPID.SetSampleTime(20);
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0,255);
}
void loop(){
//loop code that uses PID to drive motors at appropriate speed etc etc
}
How does one go about implementing the two libraries into a custom library?
E.g two files L298N.cpp and L298N.h? Below is what I’ve tried, but no luck.
L298N.cpp
#include "Arduino.h"
#include "L298N.h"
#include <RotaryEncoder.h>
#include <PID_v1.h>
L298N::L298N(char IN1, char IN2, char EN, char A_INT1, char A_INT2){
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(A_INT1), checkPosition, CHANGE);
attachInterrupt(digitalPinToInterrupt(A_INT2), checkPosition, CHANGE);
pinMode(A_INT1, INPUT);
pinMode(A_INT2, INPUT);
RotaryEncoder encoder(A_INT1, A_INT2, RotaryEncoder::LatchMode::TWO03);
PID pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
pid.SetSampleTime(20);
pid.SetMode(AUTOMATIC);
pid.SetOutputLimits(0,255);
_IN1 = IN1;
_IN2 = IN2;
_EN = EN;
}
void L298N::checkPosition(){
encoder.tick(); // just call tick() to check the state.
}
double L298N::calculate_rpm(){
long new_position = encoder.getPosition();
long position_change;
double RPM;
if (new_position != old_position) {
tick_time = (millis() - last_time);
position_change = old_position - new_position;
RPM = 1 / ((double(tick_time / position_change) * 125)/1000/60); //10041 18538 = ticks per rev, 1 rev = 42.73cm
old_position = new_position;
last_time = millis();
}
else{
RPM = 0.0;
}
delay(20); // required for dagu as encoders are shit and only pulse 125 times per rev
return RPM;
}
void L298N::set_rpm(int rpm){
Setpoint = rpm;//covert_vel_rpm(vel);
Input = calculate_rpm();
pid.Compute();
if (Setpoint > 0.0){
forwards(char(Output));
}
else{
backwards(char(Output));
}
}
void L298N::forwards(char pwm){
digitalWrite(_IN1, HIGH);
digitalWrite(_IN2, LOW);
analogWrite(_EN, pwm);
return;
}
void L298N::backwards(char pwm){
digitalWrite(_IN1, LOW);
digitalWrite(_IN2, HIGH);
analogWrite(_EN, pwm);
return;
}
L298N.h
#ifndef L298N_h
#define L298N_h
#include "Arduino.h"
#include <RotaryEncoder.h>
#include <PID_v1.h>
class L298N
{
public:
L298N(char IN1, char IN2, char EN, char A_INT1, char A_INT2);
void set_rpm(int rpm);
private:
char _IN1, _IN2, _EN, _INT1, _INT2;
double last_time = millis();
double tick_time = 0;
long old_position = 0;
double Setpoint, Output;
double Input = 0;
double Kp=1.3, Ki=15, Kd=0.01;
RotaryEncoder encoder;//(char A_INT1, char A_INT2, RotaryEncoder::LatchMode::TWO03);
PID pid;//(double &Input, double &Output, double &Setpoint, double Kp, double Ki, double Kd, char DIRECT);
void checkPosition();
double calculate_rpm();
void forwards(char pwm);
void backwards(char pwm);
};
#endif
test.ino
#include <L298N.h>
#include <RotaryEncoder.h>
#include <PID_v1.h>
char A_IN1 = 8;
char A_IN2 = 9;
char A_EN = 17;
char A_INT1 = 3;
char A_INT2 = 4;
L298N left(A_IN1, A_IN2, A_EN, A_INT1, A_INT2);
void setup(){
}
void loop(){
left.set_rpm(20);
}
errors:
Arduino: 1.8.15 (Linux), Board: "Arduino Uno"
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp: In constructor
'L298N::L298N(char, char, char, char, char)':
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:7:67: error: no
matching function for call to 'RotaryEncoder::RotaryEncoder()'
L298N::L298N(char IN1, char IN2, char EN, char A_INT1, char A_INT2)
^ In file included from
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.h:10:0,
from /home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:3:
/home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:39:3:
note: candidate: RotaryEncoder::RotaryEncoder(int, int,
RotaryEncoder::LatchMode) RotaryEncoder(int pin1, int pin2,
LatchMode mode = LatchMode::FOUR0); ^~~~~~~~~~~~~
/home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:39:3:
note: candidate expects 3 arguments, 0 provided
/home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:23:7:
note: candidate: constexpr RotaryEncoder::RotaryEncoder(const
RotaryEncoder&) class RotaryEncoder
^~~~~~~~~~~~~ /home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:23:7:
note: candidate expects 1 argument, 0 provided
/home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:23:7:
note: candidate: constexpr
RotaryEncoder::RotaryEncoder(RotaryEncoder&&)
/home/ubuntu/Arduino/libraries/RotaryEncoder/src/RotaryEncoder.h:23:7:
note: candidate expects 1 argument, 0 provided
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:7:67: error: no
matching function for call to 'PID::PID()' L298N::L298N(char IN1,
char IN2, char EN, char A_INT1, char A_INT2)
^ In file included from
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.h:11:0,
from /home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:3:
/home/ubuntu/Arduino/libraries/PID/PID_v1.h:24:5: note: candidate:
PID::PID(double*, double*, double*, double, double, double, int)
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
^~~ /home/ubuntu/Arduino/libraries/PID/PID_v1.h:24:5: note: candidate expects 7 arguments, 0 provided
/home/ubuntu/Arduino/libraries/PID/PID_v1.h:20:5: note: candidate:
PID::PID(double*, double*, double*, double, double, double, int, int)
PID(double*, double*, double*, // * constructor. links the PID to the Input, Output, and
^~~ /home/ubuntu/Arduino/libraries/PID/PID_v1.h:20:5: note: candidate expects 8 arguments, 0 provided
/home/ubuntu/Arduino/libraries/PID/PID_v1.h:5:7: note: candidate:
constexpr PID::PID(const PID&) class PID
^~~ /home/ubuntu/Arduino/libraries/PID/PID_v1.h:5:7: note: candidate expects 1 argument, 0 provided
/home/ubuntu/Arduino/libraries/PID/PID_v1.h:5:7: note: candidate:
constexpr PID::PID(PID&&)
/home/ubuntu/Arduino/libraries/PID/PID_v1.h:5:7: note: candidate
expects 1 argument, 0 provided
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:13:70: error:
invalid use of non-static member function 'void
L298N::checkPosition()'
attachInterrupt(digitalPinToInterrupt(A_INT1), checkPosition, CHANGE);
^ In file included from
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:3:0:
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.h:33:7: note:
declared here void checkPosition();
^~~~~~~~~~~~~ /home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:14:70: error:
invalid use of non-static member function 'void
L298N::checkPosition()'
attachInterrupt(digitalPinToInterrupt(A_INT2), checkPosition, CHANGE);
^ In file included from
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.cpp:3:0:
/home/ubuntu/Arduino/libraries/L298N_driver/L298N.h:33:7: note:
declared here void checkPosition();
^~~~~~~~~~~~~ exit status 1 Error compiling for board Arduino Uno.
This report would have more information with "Show verbose output
during compilation" option enabled in File -> Preferences.
Any help of how to do this properly would be greatly appreciated. It’s just using a class within a class (terminology might be wrong) but this is quite trivial to do in Python.
Cheers!
You have several problems.
You said
PID and RotaryEncoder libraries are standard arduino libraries
That's wrong, those libraries are not standard, you have to install them using the Library Manager (otherwise it would have compiled).
Those are:
- RotaryEncoder, by Mathias Hertel
http://www.mathertel.de/Arduino/RotaryEncoderLibrary.aspx
- Arduino PID Library, by Brett Beauregard
https://github.com/br3ttb/Arduino-PID-Library
Local includes should use quotes, system/external includes must use brackets:
#include "L298N.h"
#include <RotaryEncoder.h>
RotaryEncoder does not have a default constructor, so you either initialize it using the initializer list or just remove the member variable.
PID doesn't have a default constructor either.
You cannot use a class member function as an interrupt handler. This:
attachInterrupt(digitalPinToInterrupt(A_INT1), checkPosition, CHANGE);
will never work. You may have to use a singleton or similar:
L298N left(A_IN1, A_IN2, A_EN, A_INT1, A_INT2);
// code
void int_checkPosition() {
left.checkPosition()
}
// more code
// this may go in setup()
attachInterrupt(digitalPinToInterrupt(A_INT2), checkPosition, CHANGE);
I changed the code in the constructor to make it look like this and compiles.
// encoder and pid initialized properly
L298N::L298N(byte IN1, byte IN2, byte mEN, byte A_INT1, byte A_INT2)
: encoder((int)A_INT1, (int)A_INT2, RotaryEncoder::LatchMode::TWO03)
, pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT)
{
piL298N::L298N(byte IN1, byte IN2, byte EN, byte A_INT1, byte A_INT2)
: encoder((int)A_INT1, (int)A_INT2, RotaryEncoder::LatchMode::TWO03)
, pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT)
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN, OUTPUT);
// this doesn't work (use the recommendation above)
//attachInterrupt(digitalPinToInterrupt(A_INT1), checkPosition, CHANGE);
//attachInterrupt(digitalPinToInterrupt(A_INT2), checkPosition, CHANGE);
pinMode(A_INT1, INPUT);
pinMode(A_INT2, INPUT);
// you don't need this. in fact, it wasn't going to work
// because you needed it to be a class member.
//RotaryEncoder encoder((int)A_INT1, (int)A_INT2, RotaryEncoder::LatchMode::TWO03);
//PID pid(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
pid.SetSampleTime(20);
pid.SetMode(AUTOMATIC);
pid.SetOutputLimits(0,255);
_IN1 = IN1;
_IN2 = IN2;
_EN = EN;
}
It is up to you to fix the issue with the interrupt handler.
i think I understand what are you asking. Arduino (and many other IDE) has two different types o library
1) Local libraries
2) External Libraries
Local Libraries are those that you include by the syntaxis:
#include "Your_library.h"
External Libraries are those with the syntaxis:
#include <Your_library.h>
The difference between them is that the Local Libraries are supposed to be in the same folder of the proyect, it means that if you have a folder
Arduino/My_proyect/My_Proyect.ino
the library should be in
Arduino/My_proyect/Your_library.h
Instead, external Libraries are in the Arduino "libraries" folder
Arduino/libraries/Your_library/Your_library.h
Maybe the problem with your code is that you are using the bad type of syntaxis for the library, try to put all the libraries you want to use (.h and .cpp) in the same file and create a folder in the arduino "libraries" folder, then, include your librarys using the external syntaxis
#include <Folder_name.h>
This should work!

g++ was not declared in this scope

I im writing sqlite3 wrapper with class to read db file. I im using ubuntu 64-bit and g++ compiler...and when i run code above i get this:
g++ ezserver.cpp -lsqlite3 -o ezserver
ezserver.cpp: In function int main():
ezserver.cpp:7:2: error: DataBase was not declared in this scope
DataBase = new EZServer();
^
database.h
#ifndef DATABASE_H
#define DATABASE_H
/* LIBRARY */
#include <sqlite3.h>
/* CLASS */
class EZServer {
public:
EZServer();
~EZServer();
int OpenDataBase(const char *TFileName);
int CreateDataBase(const char *TFileName);
private:
sqlite3 *DataBase;
sqlite3_stmt *QueryHandle[2];
};
#endif
database.cpp
#include "database.h"
/* CONSTRUCTOR */
EZServer::EZServer(): DataBase(0) {
QueryHandle[0] = NULL;
QueryHandle[1] = NULL;
}
/* DESTRUCTOR */
EZServer::~EZServer() {
/* CLOSE - database */
if (DataBase) {
sqlite3_close(DataBase);
}
}
/* LOAD - database file */
int EZServer::OpenDataBase(const char *TFileName) {
/* OPEN - database */
int Result = sqlite3_open_v2(TFileName, &DataBase, SQLITE_OPEN_READWRITE, NULL);
/* CHECK - database */
if (Result != SQLITE_OK) {
printf("OpenDataBase: %s\n", sqlite3_errmsg(DataBase));
sqlite3_close(DataBase);
return 0;
}
return 1;
}
/* CREATE - database file */
int EZServer::CreateDataBase(const char *TFileName) {
/* OPEN - database */
int Result = sqlite3_open_v2(TFileName, %DataBase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
/* CHECK - database */
if (Result != SQLITE_OK) {
printf("OpenDataBaseCreate: %s\n", sqlite3_errmsg(DataBase));
sqlite3_close(DataBase);
return 0;
}
return 1;
}
ezserver.h
#ifndef EZSERVER_H
#define EZSERVER_H
/* FORWARD - declarations */
class EZServer;
/* CLASS */
class StatsClass {
public:
int Init();
private:
EZServer *DataBase;
};
#endif
ezserver.cpp
#include "ezserver.h"
#include "database.h"
int main() {
DataBase = new EZServer();
}
main file is ezserver.cpp.
i im beginner in c++ so i read posts here try solutions but always get DataBase was not declared in this scope...could some one give solution?
Thanks.
EDIT:
I need to call EZServer() class name that holds functions like OpenDataBase CreateDataBase.
// Load database that opens save and query
Database = new EZServer();
Database->OpenDatabase("ezserver.db");
so i need this above ->OpenDataBase to be called from EZServer.cpp (main file program) and return from class EZServer value that function is defined in database.cpp
I found another problem, you should compile all *.cpp files.
g++ ezserver.cpp database.cpp -lsqlite3 -o ezserver
here is log when i run this:
g++ ezserver.cpp database.cpp -lsqlite3 -o ezserver database.cpp:4:20:
error: definition of implicitly-declared ‘EZServer::EZServer()’
EZServer::EZServer(): DataBase(0) { ^ database.cpp:10:21: error:
definition of implicitly-declared ‘EZServer::~EZServer()’
EZServer::~EZServer() { ^ database.cpp: In member function ‘int
EZServer::OpenDataBase(const char*)’: database.cpp:20:76: error:
‘NULL’ was not declared in this scope int Result =
sqlite3_open_v2(TFileName, &DataBase, SQLITE_OPEN_READWRITE, NULL); ^
database.cpp:24:56: error: ‘printf’ was not declared in this scope
printf("OpenDataBase: %s\n", sqlite3_errmsg(DataBase)); ^
database.cpp: In member function ‘int EZServer::CreateDataBase(const
char*)’: database.cpp:34:42: error: expected primary-expression
before ‘%’ token int Result = sqlite3_open_v2(TFileName,
%DataBase, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); ^
database.cpp:34:97: error: ‘NULL’ was not declared in this scope
int Result = sqlite3_open_v2(TFileName, %DataBase,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); ^
database.cpp:38:62: error: ‘printf’ was not declared in this scope
printf("OpenDataBaseCreate: %s\n", sqlite3_errmsg(DataBase)); ^
Maybe you should write something like this:
EZServer* dataBase = new EZServer();
dataBase->OpenDataBase("ezserver.db");

"RpcAsync.h" header file not being read, in which I have put in order for recognizing AnsiString in Microsoft Visual Studio

This is my first time working with header files, and I have a source code and I'm trying to include RpcAsync.h file and written in the beginning of my source file.
However Visual Studio is not recognizing the header file for AnsiString. I am able to see AnsiString definitions in RpcASync.h .
It throws an error saying :
1 IntelliSense: identifier "AnsiString" is undefined.
I did include the file in the solution. and I did used std::string it doesn't serve the purpose.
AnsiString has been declared in header file RpcASync.h as :
typedef struct tagRPC_EE_INFO_PARAM
{
union
{
LPSTR AnsiString;
} u;
}
In CPP file I have included RpcASync.h header file and tried to access AnsiString as a parameter in function as follows
bool FindRunningProcess(AnsiString process)
{
AnsiString compare;
if (pe32.szExeFile == process) {
procRunning = true;
} else {
// loop through all running processes looking for process
while (Process32Next(hProcessSnap, &pe32)) {
// Set to an AnsiString instead of Char[] to make compare easier
compare = pe32.szExeFile;
if (compare == process) {
// if found process is running, set to true and break from loop
procRunning = true;
break;
}
but when I compile it throws an error -
IntelliSense: identifier "AnsiString" is undefined.
Note : pe32.szExeFile is of WCHAR , So I am using process as AnsiString

A newbie and the timer module that doesn't compile

I'm totally new to C/C++. I've done some higher languages like Java and C# but that's something else I must say. I'm trying to build a timer module for the Arduino so that I can easily queue work that has to be executed after a certain amount of time without the use of delay(). I would like to create it as intuitively as possible so that I can easily re-use it.
So far I've tried a lot of different approaches. What I did is mostly read tutorials on how to achieve a certain thing in C/C++ and created my little project out of that.
Main .ino file:
#include "Timer.h"
Timer timer;
void setup()
{
// Init the timer
timer.init();
pinMode(13, OUTPUT);
// Define the state
int state = 1;
// Create the action
TimerAction action;
action.create(1000, &timerElapsed, 1 -1);
action.state = &state;
}
void loop()
{
timer.run();
}
void timerElapsed(TimerAction action) {
int *state = (int*)action.state;
if (state == 0) {
digitalWrite(13, HIGH);
*state = 1;
}
else
{
digitalWrite(13, LOW);
*state = 0;
}
}
It's very simple. I'm trying to blink the onboard led as a proof of concept.
This is the Timer.h file:
#ifndef _TIMER_h
#define _TIMER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
struct Timer {
TimerAction* actions;
uint8_t size;
void init();
void queue(TimerAction action);
void dequeue(TimerAction action);
void dequeueIdx(int idx);
void run();
};
struct TimerAction {
// Sets whether to repeat the action
uint8_t repetitive;
// Sets how many times to repeat the action, -1 for infinite
// Will only be used when repetitive == 1
long finite;
void (*callback)(TimerAction sender);
void *state;
unsigned long last;
unsigned long interval;
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
};
#endif
This is the Timer.ino file:
#include "Timer.h"
void Timer::init() {
size = 0;
actions = new TimerAction[10];
}
void Timer::queue(TimerAction action) {
action.last = millis();
actions[size - 1] = action;
size++;
}
void Timer::dequeue(TimerAction action) {
for (int i = 0; i < size; i++)
if (&(actions[i]) == &action) {
memmove(actions + i, actions + i + 1, (size - (i + 1)) * sizeof(TimerAction));
break;
}
}
void Timer::dequeueIdx(int idx) {
memmove(actions + idx, actions + idx + 1, (size - (idx + 1)) * sizeof(TimerAction));
}
void Timer::run() {
for (int i = 0; i < size; i++)
if ((actions[i].last + actions[i].interval) >= millis()) {
TimerAction action = actions[i];
action.callback(action);
if (action.repetitive == 1) {
if (action.finite > 0)
action.finite--;
else
if (action.finite == 0)
dequeueIdx(i);
}
else
dequeueIdx(i);
}
}
void TimerAction::create(long _interval, void(*_callback)(TimerAction sender),
uint8_t _repetitive = 0U, long _finite = -1L) {
interval = _interval;
callback = _callback;
repetitive = _repetitive;
finite = _finite;
}
These are the errors the compiler spewed out:
Arduino: 1.6.1 (Windows 8.1), Board: "Arduino Uno"
In file included from Stoplicht.ino:1:0:
Timer.h:13:2: error: 'TimerAction' does not name a type
TimerAction* actions;
^
Timer.h:17:13: error: 'TimerAction' has not been declared
void queue(TimerAction action);
^
Timer.h:18:15: error: 'TimerAction' has not been declared
void dequeue(TimerAction action);
^
Timer.ino: In member function 'void Timer::init()':
Timer.ino:5:2: error: 'actions' was not declared in this scope
Timer.ino: At global scope:
Timer.ino:8:6: error: prototype for 'void Timer::queue(TimerAction)' does not match any in class 'Timer'
In file included from Stoplicht.ino:1:0:
Timer.h:17:7: error: candidate is: void Timer::queue(int)
void queue(TimerAction action);
^
Timer.ino:15:6: error: prototype for 'void Timer::dequeue(TimerAction)' does not match any in class 'Timer'
In file included from Stoplicht.ino:1:0:
Timer.h:18:7: error: candidate is: void Timer::dequeue(int)
void dequeue(TimerAction action);
^
Timer.ino: In member function 'void Timer::dequeueIdx(int)':
Timer.ino:24:10: error: 'actions' was not declared in this scope
Timer.ino: In member function 'void Timer::run()':
Timer.ino:29:8: error: 'actions' was not declared in this scope
Timer.ino: At global scope:
Timer.ino:45:52: error: default argument given for parameter 3 of 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
In file included from Stoplicht.ino:1:0:
Timer.h:36:7: error: after previous specification in 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
^
Timer.ino:45:52: error: default argument given for parameter 4 of 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
In file included from Stoplicht.ino:1:0:
Timer.h:36:7: error: after previous specification in 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
^
Let me explain why I'm using Array over a std::vector. My chain of thought was this: the Arduino is quite weak and actions is going to be accessed a lot. So I thought it's a bit more work to implement it initially but it will make sure the timer doesn't use too much of the Arduino's resources.
I've tried a lot of things but I don't really understand where the problem lies. So that's why I'm asking an expert to look at my code and maybe put me on the right track.
In Timer.h you have:
TimerAction* actions;
At the point in time that the compiler sees that line of code it has not seen what a TimerAction is. As such it does not know what the type is and is giving you an error. What you need to do is forward declare TimerAction before Timer so the compiler knows what it is doing.
#ifndef _TIMER_h
#define _TIMER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
struct TimerAction;
struct Timer {
//...

Unix errors running C++ program involving struct tm

I wrote an Inventory program for groceries in C++ using Visual Studio 2012 and
everything runs smoothly and as expected. A file is read in as a command line argument and that is used to fill a deque with Grocery objects. A function that I used to check if a Grocery object was expiring soon used time_t and struct tm. When trying to run my program on Unix, I get an error involving fstream
Here are the lines of code where I am getting the errors:
int main (int argc, char** argv) {
deque<Grocery> groceries;
deque<Grocery>::iterator iter;
string filename = "";
if (argc > 1) {
filename = argv[1];
fstream fileData;
fileData.open(filename, ios::in | ios::out); //**error**
//error check
if (!fileData) {
cout << "Error openeing file. Program aborting.\n";
return 1;
}
string name;
string expDate;
string type;
string quantity;
while (!fileData.eof()) {
Grocery temp;
getline (fileData,name,'\t');
temp.setName(name);
getline (fileData,expDate,'\t');
temp.setExpDate(expDate);
getline (fileData,type,'\t');
temp.setType(type);
getline (fileData, quantity,'\n');
temp.setQuantity(atoi (quantity.c_str()));
groceries.push_back(temp);
}
fileData.close();
}
return 0;
}
Errors when trying to run program in Unix
$ make all
g++ -c Grocery.cpp
g++ -c Inventory.cpp
Inventory.cpp: In function âint main(int, char**)â:
Inventory.cpp:24:45: error: no matching function for call to âstd::basic_fstream<char>::open(std::string&, std::_Ios_Openmode)â
fileData.open(filename, ios::in | ios::out);
^
Inventory.cpp:24:45: note: candidate is:
In file included from Inventory.cpp:3:0:
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.1/fstream:886:7: note: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
open(const char* __s,
^
/opt/rh/devtoolset-2/root/usr/include/c++/4.8.1/fstream:886:7: note: no known conversion for argument 1 from âstd::string {aka std::basic_string<char>}â to âconst char*â
make: *** [Inventory.o] Error 1
Makefile
MKFILE = Makefile
#
# Definitions of list of files:
#
HSOURCES = Grocery.h
CSOURCES = Grocery.cpp Inventory.cpp
ETCSRC = README ${MKFILE}
EXECBIN = main
ALLCSRC = ${CSOURCES}
OBJECTS = ${ALLCSRC:.cpp=.o}
ALLSRC = ${ETCSRC} ${HSOURCES} ${CSOURCES}
LISTSRC = ${ALLSRC}
#
# Definitions of the compiler and compilation options:
#
GCC = g++
#
# The first target is always ``all'', and hence the default,
# and builds the executable images
#
all : ${EXECBIN}
#
# Build the executable image from the object files.
#
${EXECBIN} : ${OBJECTS}
${GCC} -o ${EXECBIN} ${OBJECTS}
#
# Build an object file form a C source file.
#
%.o : %.cpp
${GCC} -c $<
#
# Clean and spotless remove generated files.
#
clean :
- rm -rf ${EXECBIN} ${OBJECTS}
FIXED
Answer listed below
Inventory.cpp:24:45: error: no matching function for call to âstd::basic_fstream<char>::open(std::string&, std::_Ios_Openmode)â
fileData.open(filename, ios::in | ios::out);
basic_fstream(const string&, ios_base::openmode) constructor is only available in C++11 mode.
You are compiling your code in C++98 mode. Pass -std=gnu++11 to g++ when compiling.
I think you need a clean build.
Since you have the declarations in header file, and you might have changed the expDate from type tm to tm*.