Thursday, May 10, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...