hi,
I am sort of new to arduino, and i seem to be having problems with something that should be very simple.. Help!
The project is controlling an LED matrix in the form of a map, lighting an LED according to a particular event in that time and place in that map.
I am trying an array of object 'incident' with each one having 2 elements "time" (an int) and "place" (another int). I then want to declare the array and its elements and be able to get the time and place for each incident.
I created a class incident, with its getTime and getPlace functions, and i included the header file, all this seems fine. Then when i declare an array of incidents, i am getting errors, and not sure how to access each element.
Can anyone help? Am i making a mistake in the class? am i making a mistake in instantiating the variable in the main file? How do i proceed from here and access the elements of the array with thier variables?
Also, If such a class is not a good idea, should i do a two-dimensional array instead?
i am on a tight deadline, and would really appreciate the help,
thanks a lot,
ayah
Here is my header file:
/**
*create an incident class
*/
#ifndef incident_h #define incident_h
// the #include statment and code go here...
class incident
{
public:
incident(int time, int place);
void getTime(void);
void getPlace(void);
private:
int _time;
int _place;
};
#endif
Here is my cpp file:
#include "incident.h"
incident::incident(int time, int place)
{
_time = time;
_place = place;
}
void incident::getTime()
{
}
error: no matching function for call to 'incident::incident()'/Applications/arduino-0011/hardware/libraries/incident/incident.h:13: note: candidates are: incident::incident(int, int)
Short answer : AFAIK, you can't do it this way. Your class includes only one
constructor, which take parameters you can't provide in an array definition. You need to make an array of pointers, not an array of your class.
Or just make your constructor do nothing and provide an init() method. I think then you'd be able to make an array of objects (though I haven't actually tried it).
Or just make your constructor do nothing and provide an init() method. I think then you'd be able to make an array of objects (though I haven't actually tried it).
Ben
It works - this is the way I figured out how to do it when faced with the same issue and not knowing any other way to do it.