i`m having this structure(array) which i want to fill with Class objects. What is the procedure to acomplish that. The tutorials i used/books weren’t that detailed and i don’t know how to do that.(since my tries failed)
ARRAY STRUCT
struct.h
struct Arr{
int days;
int *M;
};
typedef Arr* Array;
struct.cpp
void constr(Array &o){
//Construct of 1*31 Matrix
o=new Arr;
o->days = days;
o->M = new int[o->days];
CLASS
expe.h
class Expe {
private:
int *obj;
public:
Expe();
~Expe();
void setObj(int ,int ,int ,int ,int ,int);
void printObj();
int getObj();
enter code here
expe.cpp
Expe::Expe() {
this->obj=new int[6];
}
Expe::~Expe() {
delete this->obj;
}
ps: I need to use my own struct vector.h is not allowed, and it has to be dyanmical
As the code is now, your
Arrstruct can hold an array of integers. If you want it to holdExpeobjects you can define it as:or, better yet, make it a template class:
I also suggest moving the constructor inside the
structinstead of the methodconstr:By using a template, you can specialize
Arrhowever you want:As a side-note, since this isn’t PHP, the
this->is not really necessary inside the class context, unless you have a local variable with the same name as a member, which you don’t.