creating an array of user defined classes

I keep getting this error, please help

expected unqualified-id before '[' token


struct User // standard phone used to unlock the lock, not able to add new users
{
public:
static String Name; // user name
static String Number; // user mobile no.
static boolean Temporary; // will the user have full access or a single use code? 1 = single use
};

static User[] Users = new User[4];

thanks in advanced!

You don't want to create a User[4] but 4 users...

User users[4];

And why static? And why all public? And why String class?

I haven got a clue tbh!! thanks for the help

What do you want the class to do?

basically I am creating a lock that can be communicated with using SMS and the class needs to be set up for 4 users with name, number and whether or not the users access to the lock is temporary (delivery man). As the users will all use the same data types i am creating a class and as there will be 4 I wanted to add them to an array to make it easier to save them as I am planning to save them to the arduinos eeprom.

Okay, sounds good. BUT, a class with only some data isn't that useful. Add functions to do something with the info. For example a check to see if the number matches.

The whole idea from a class (or better, objects) are the encapsulate the data. So no public variables. And use a getter and setter to for example check the data before using it.

Also, I would not use String...

okay great thanks for the help, it's for a school computer science project here is the code I have so far..

#include <SoftwareSerial.h> // include the library SoftwareSerial.h to allow another serial connection

SoftwareSerial GPRS(7, 8); //RX, TX serial connections to SMS module
boolean MagSwitch; // Pin 2
boolean MomentButton; // Pin 3
boolean Relay; // Pin 4
const int MagSwitchPin = 2;
const int MomentButtonPin = 3;
const int RelayPin = 4;
String AdminNumber; // admin mobile no.

struct User // standard phone used to unlock the lock, not able to add new users
{
static String Name; // user name
static String Number; // user mobile no.
static boolean Temporary; // will the user have full access or a single use code? 1 = single use
};

new User[] = User1;

void setup() // runs through this function once after power up, used to set pin values etc.
{
pinMode(MagSwitchPin, INPUT); // MagSwitch
pinMode(MomentButtonPin, INPUT); // MomentButton
pinMode(RelayPin, OUTPUT); // Relay

GPRS.begin(9600); // Starts a serial communication with the SMS module
Serial.begin(9600); // Starts a serial communication with the connected USB COM port

GPRS.println("AT + CMGF = 1"); // checks to see if the connected modem supports SMS if true the modem returns OK

delay(1000); // wait 1000ms
//GPRS.println("AT + CPIN = "0000" "); // unlocks SIM if protected by a PIN code otherwise comment this line

delay(1000); // wait 1000ms
}

void loop() // consecutively run this function over and over hence the identifier "loop"
{

}

static void PairNewAdmin() // Puts the program in a state where it scans the last recieved message for 30 seconds and if the SMS content is PAIR then sets the sender as Admin
{
boolean Changed = 0; // if 1 a new device has been paired
{
sendSMS(AdminNumber, "request to pair new device"); // tels the existing admin the lock is being paired to a new device
}

do
{
int i = 0; // temporary variable to store count
delay(1000); // wait 1000ms
i++; // i + 1

if (Content == "PAIR")
{
AdminNumber = Sender;
Changed = 1;
i = 30;
sendSMS(AdminNumber, "DEVICE PAIRED TO LOCK"); // tell the requester that they have been successfull
Serial.println("New device paired - " + Sender); // inform the serial moniter of the new admin
}
}while(i < 30); // loops for 30 seconds unless i is changed by anything other than i++
}

static void CommandRecieved(String Sender, String Content)
{
String Command = Content.Substring(0,3);
String Number = Content.Substring(4,16);
String Temporary = Content.Substring(17);

if

if (Sender == AdminNumber || Sender == User[1].Number || Sender == User[2].Number || Sender == User[3].Number || Sender == User[4].Number)
{
if (Command == OPEN)
{
Unlock();
if (User);
}
else if (Command ==
}
else
{
sendSMS(Sender, "Sorry, your number has not been recognised by the lock please contact your system admin.");
sendSMS(AdminNumber, "An unrecognised number (" + Sender + ") tried to access the lock with the content " + Content); // inform the admin of another number trying to access lock
}
}

static void sendSMS(String SendTo, String Content) // the function that will be used to send an SMS to the number given in parameter "SendTo" with the content in parameter "Content"
{
GPRS.println("AT + CMGF = 1"); // Puts the modem in a mode ready to send an SMS
GPRS.println("AT & CMGS = " + SendTo + "+"); // tells the modem who to send the SMS to, should return >
GPRS.println(Content); // Sends the content of the SMS to the modem
GPRS.write( 0x1a ); // Hexadecimal ctrl+Z character used to send an SMS
}

static void recieveSMS(byte MessageLocation) // the function that will be used to view incoming and recieved SMS messages with "MessageLocation" being the address on the SIM card where the desired message is stored
{
GPRS.println("AT + CMGF = 1"); // Puts the modem in a mode ready to recieve an SMS
GPRS.println("AT + CPMS = "SM""); // sets the default storage location for new messages as the SIM card, usually SIM cards can store upto 15 messages
GPRS.println("AT & CMGL = "ALL""); // lists all of the messages found on the default storage device
GPRS.println("AT CMGR + " + MessageLocation);
}

static void ClearSIM(byte SIMAddress) // the function that wil be used to remove the content from address X on the SIM card with "SIMAddress being location X"
{
GPRS.println("AT CMGR + " + SIMAddress + " ="); // removes the message from "SIMAddress" on the SIM card
Serial.println("Cleared message from address " + SIMAddress + " on the primary storage device"); // prints a new line on the serial monitor to confirm that address X has been cleared
}

static void Unlock(String User) // this function opens the lock and sends a notification to the admin stating which user unlocked the lock
{
delay(1000); // wait 1000ms
Serial.println("System unlocking"); // prints into the serial monitor for debugging purposes
delay(100); // wait 100ms
digitalWrite(RelayPin, HIGH); // apply 5v to the relay causing the solonoid to activate releasing the lock
delay(2000); // leave the door unlocked for 2000ms
digitalWrite(RelayPin, LOW); // stop applying 5v to the relay
sendSMS(Admin[Number], "The lock was opened by " + User); // send an SMS to Admin informing which user unlocked door
}

Is there anything significant that you can spot that you would change?

Also why not use a string?

Again Thanks, This forum is a great resource to have especially with such a friendly helpful community!!!

Do not use static on the data members if you want each class to have its own data.
The way you declare it all users share the same data.

@Delta_G - right that makes sense, thanks! What would you suggest doing instead?

@Whandall - okay thanks, big help

Ok thanks @Delta_G

How would I go about writing information into the array?

char myCString[20] = "Start like this"
//add a !
myCString[15] = '!';

//Whole string
strcpy(myCString, "Now it's like this"

//or, if the new string might be to long (we can't have more then 19 char (20-1 null char))
strncpy(myCString, "End like this but this might be to long to fit", 19);
myCString[19] = '\0'; //te be sure it has a proper end

great thanks