I'm looking to make some upgrades to a library but i have not worked a lot with classes. The problem i'm having is i have a bunch of ring buffer code that i'm trying to recycle. The ring buffer code works by handing a function a struct by reference, the function then modifies the struct. the code is very flexible this was because a single function can be handed many different structs as long as the structure of the struct is the same. for example..
void ringBuf_put(struct ringBuf * _this, int data){ some stuff..}
struct ringBuf{
int buffer[10];
int head;
int tail;
int count;
};
struct ringBuf one;
struct ringBuf two;
ringBuf_put(&one, 17);
ringBuf_put(&two, 21);
This code works perfectly fine in arduino environment. Now i'm trying to wrap this same code into a class to use in a library and it's not working. if i try to compile this code in the library or just in arduino i get an error. (this is just test code but the real code is almost identical but much longer)
FastTransferTest:21: error: prototype for 'void fast::otherstuff(fast::test*)' does not match any in class 'fast'
FastTransferTest:7: error: candidate is: void fast::otherstuff(test*)
class fast{
public:
void stuff(int hi);
private:
void otherstuff(struct test * hy);
struct test{
int th;
int irm;
};
test kick;
};
void fast::stuff(int hi){
}
void fast::otherstuff(struct test * hy){
}
void setup()
{
}
void loop()
{
}
but if i compile this code it compiles just fine.
class fast{
public:
void stuff(int hi);
private:
//converting the struct pointer to an integer is the only change
void otherstuff(int hy);
struct test{
int th;
int irm;
};
test kick;
};
void fast::stuff(int hi){
}
//converting the struct pointer to an integer is the only change
void fast::otherstuff(int hy){
}
void setup()
{
}
void loop()
{
}
is it not possible to pass a struct by reference inside a class or am i doing something wrong?
maybe a library that i need to add?
In file included from C:\Users\NASSAR K I\Documents\Arduino\libraries\Moving_clcock_working\DS3231.cpp:22:0:
C:\Users\NASSAR K I\Documents\Arduino\libraries\Moving_clcock_working\DS3231.h:27:42: fatal error: hardware/avr/HW_AVR_defines.h: No such file or directory
#include "hardware/avr/HW_AVR_defines.h"
^
compilation terminated.
Multiple libraries were found for "RTClib.h"
Used: C:\Users\NASSAR K I\Documents\Arduino\libraries\RTClib
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\RTCLib_by_NeiroN
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\NASSAR K I\Desktop\arduino-1.8.3\hardware\arduino\avr\libraries\SoftwareSerial
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\EspSoftwareSerial
Multiple libraries were found for "Adafruit_GFX.h"
Used: C:\Users\NASSAR K I\Documents\Arduino\libraries\Moving_clcock_working
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\LEDDotMatrixClock
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\LEDDotMatrixClock
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\LEDDotMatrixClock
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\LEDDotMatrixClock
Not used: C:\Users\NASSAR K I\Documents\Arduino\libraries\Adafruit-GFX-Library-master
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This sketch not compiling please help