Creating Objects

I’ve been trying to understand some of the previous topics posted on this but I can’t figure out how to do it.
Here’s what I’ve attempted to do:

void setup() 

void object(int x, int y)
  int Long = x;
  int Lat = y;

void loop()
  object object1(1,2);

I wanted to be able to later do something like

int a = object1.Long
int b = object1.Lat

Any help would be greatly appreciated

The entity you have called "object" is not an object, it is a function, so as soon as "object" returns, "Lat" and "Long" go out of scope and are lost.

It isn't clear whether you need a C "struct" or a C++ "class" (but those are useful search terms)

As mentioned, a struct might solve your problems:

struct Location
  int Lat;
  int Long;

struct Location here={125,-100}, there={34,90};

int a = here.Long;
int b = here.Lat;
int c = there.Long;
int d = there.Lat;

A class is actually somewhat like a structure with functions. So, if all you want to do is store information like this, a struct will do - but if you plan to do more intensive fiddling with the data, a class may be handier.

A class is actually somewhat like a structure with functions.

Both can have functions, the only difference is for a structure, members are public by default, whereas a for class, members are private by default.

Thanks for the help guys, that was exactly what I was after. Didn’t know what arduino defined it as.
Managed to create an array of them which I was surprised arduino could do :slight_smile:
May change it to a class if scope/security becomes a concern.