I defined a class called HPC_user as follows:
#include <iostream.h>
#include <string>
using std::string;
class HPC_user
{
public:
HPC_user(std::string firstName, std::string lastName, std::string login, std::string school, double activity);
~HPC_user();
std::string get_first() const { return fName; }
void set_first(std::string first) { fName = first; }
std::string get_last() const { return lName; }
void set_last(std::string last) { lName = last; }
std::string get_login() const { return uId; }
void set_login(std::string login) { uId = login; }
std::string get_school() const { return sName; }
void set_school(std::string school) { sName = school; }
std::string get_activity() const {return cpuTime; }
void set_activity(std::string activity) { cpuTime = activity; }
private:
std::string fName, lName, uId, sName, cpuTime;
};
HPC_user.cpp
#include "HPC_user.h"
// constructor of HPC_user
HPC_user::HPC_user(std::string firstName, std::string lastName, std::string login, std::string school, double activity)
{
fName = firstName;
lName = lastName;
uId = login;
sName = school;
cpuTime = activity;
// cout << "new HPC_user created\n";
}
HPC_user::~HPC_user() // destructor
Now I want to allocate an array of 500 HPC_user objects and set the elements to NULL or 0.0 first. Then assign real values in a for loop.
This is what I did:
int size = 500;
HPC_user *users;
users = new HPC_user(NULL,NULL,NULL,NULL,0.00)[size];
I got an error while compiling it:
db2class.cpp:51:49: error: expected ';' after expression
users = new HPC_user(NULL,NULL,NULL,NULL,0.00)[size];
What is the correct way to allocate space for an array of objects?