Hi there I need to Build something like a dictionary and each word according to my code can have 100 meanings, but maybe it has only 5 meanings then I will be allocating 95 extra space for nothing or maybe it has more than 100 meanings then the program will crash, I know the vector class is very easy and could be good use of, but the task is almost building my own vector class, to learn how it works. Thus \*\*meanings and some other stuff remain the same and here is my code, Also I know I am causing memory leakage, how can I delete properly? :

```
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

class Expression {

    char *word_with_several_meanings; // like "bank", "class"
    char **meanings; // a pointer to a pointer stores all meanings
    int meanings_ctr; // meanings counter

    //-----------FUNCTIONS------------------------------------------------
public:
    void word( char* = NULL );
    void add_meaning(char* = NULL);
    char* get_word();
    int get_total_number_of_meanings();
    char* get_meaning(int meanx = 0);
    Expression(int mctr = 0); // CTOR
    ~Expression(); // DTOR
};

  Expression::Expression(int mctr ) {
  meanings_ctr = mctr;          // Setting the counter to 0
  meanings = new char * [100]; // Allocate Space for 100 meanings
}

Expression::~Expression() {
 delete [] meanings; // Deleting the memory we allocated
 delete [] word_with_several_meanings; // Deleting the memory we allocated
}

void Expression::word( char *p2c )
{

    word_with_several_meanings = new char[strlen(p2c)+1];
// copy the string, DEEP copy
    strcpy(word_with_several_meanings, p2c);
}

void Expression::add_meaning(char *p2c)
{

    //meanings = new char * [meanings_ctr+1];
    meanings[meanings_ctr] = new char[strlen(p2c)+1];
    strcpy(meanings[meanings_ctr++],p2c);

}

char * Expression::get_meaning( int meanx )
{

    return *(meanings+meanx);

}

char * Expression::get_word()
{

    return word_with_several_meanings;

}

int Expression::get_total_number_of_meanings()
{

    return meanings_ctr;

}

int main(void) {
    int i;
    Expression expr;
    expr.word("bank ");
    expr.add_meaning("a place to get money from");
    expr.add_meaning("b place to sit");
    expr.add_meaning("4 letter word");
    expr.add_meaning("Test meaning");
    cout << expr.get_word() << endl;

    for(int i = 0; i<expr.get_total_number_of_meanings(); i++)
            cout << " " << expr.get_meaning(i)  << endl;
    Expression expr2;
    expr2.word("class");
    expr2.add_meaning("a school class");
    expr2.add_meaning("a classification for a hotel");
    expr2.add_meaning("Starts with C");
    cout << expr2.get_word() << endl;
    for( i = 0; i<expr2.get_total_number_of_meanings(); i++)
            cout << " " << expr2.get_meaning(i) << endl;

        Expression expr3;
    expr3.word("A long test ... ");
    char str[] = "Meaning_      ";
    for (int kx=0;kx<26;kx++)
    {
            str[8] = (char) ('A'+kx);
            expr3.add_meaning(str);
    }

cout << expr3.get_word() << endl;
for(i = 0; i < expr3.get_total_number_of_meanings(); i++)
    cout << " " << expr3.get_meaning(i) << endl; 

    return 0;
}

```