I want to calculate the days that passed in a year since a certain date. I made a class DayNumber.
i made this header file
#ifndef DayNumber_H_
#define DayNumber_H_
class DayNumber
{
private:
int _day1YearLoop[];
int _day4YearLoop[];
public:
int Days1YearLoop;
int Days4YearLoop;
DayNumber(int setYear,int setMonth,int setDay);
virtual ~DayNumber();
bool checkLeapYear(int setYear);
};
#endif
i use eclipse. and i made this .cpp file.
#include "DayNumber.h"
DayNumber::DayNumber(int setYear,int setMonth,int setDay){
// it does not matter what it does it just give me the number of the day since 1 january of each year for a certain day.
}
DayNumber::~DayNumber(){
}
bool DayNumber::checkLeapYear(int setYear){
if (setYear%4==0){
return true;
}
else{
return false;
}
}
the problem is at the main.cpp. When i do:
void loop() {
DayNumber num1 = DayNumber(2715,10,23);
Serial.print("Days for one Year Loop(leap)\t");
Serial.print(num1.Days1YearLoop);
delay (5000);
}
everything is ok. if i try to declare DayNumber num1; befroe everything. i mean before setup like this:
#include "Arduino.h"
#include "DayNumber.h"
DayNumber num1;
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
void setup() {
Serial.begin(9600);
}
void loop() {
DayNumber num1 = DayNumber(2715,10,23);
Serial.print("Days for one Year Loop(leap)\t");
Serial.print(num1.Days1YearLoop);
delay (5000);
}
i get this error:
../src/main.cpp:8: error: no matching function for call to 'DayNumber::DayNumber()'
/Volumes/Lion 2/EclipseWorks/DayNumber/lib/DayNumber.h:22: note: candidates are: DayNumber::DayNumber(int, int, int)
/Volumes/Lion 2/EclipseWorks/DayNumber/lib/DayNumber.h:12: note: DayNumber::DayNumber(const DayNumber&)
make: *** [src/main.o] Error 1
line 22 at header is DayNumber(int setYear,int setMonth,int setDay);
and line 12 is class DayNumber{
so why is this happening? i did everything by the tutorial of from the site and i mean arduino for making libraries. I just wanted to define an "object" of this class to use it in loop.i have made an RTC (real time clock) and i am also using its library that does the same ( defines the object of RTC class before everything) and it does not give any problem. Can you give me a solution so i can declare the object without initialization and then call it inside loop and initialize it?