Thursday, 10 May 2018

Errors when initializing class with an array as a member variable in C++

I'm just starting to learn C++ and can't figure out what I'm doing wrong.




I'm trying to build a class "Holder" that holds an array of up to 100 of another class "Obj". I have the following two classes:



class Obj {
public:
Obj(int k, char v): key(k), val(v) {};
private:
int key;
char val;


friend class Holder;
};


class Holder {
private:
enum {MAX_SIZE = 100};
Obj p[MAX_SIZE];
int pSize = 0;
public:

Holder();
~Holder();
//...
};


When initializing the class Holder from main(), as follows...



int main() {
Holder test;


return 0;
}


I'm receiving these errors after running the program:



undefined reference to "Holder::Holder()" and
undefined reference to "Holder::~Holder()"




I can't tell if I'm correctly using an array as a class member variable in "Holder"? Or if I'm missing something in the constructor?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...