Declaring size of array in constructor

Hello, I'm currently implementing class using C++ string.

Now, as private members of this class I have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class MyClass
{
  private:
    string key[];
    string val[];

  public:
    MyClass(int s)
    {
      //here I want to allocate key and val string arrays to hold s number of 
      //elements
      string key[s];
      string val[s];
      //How do I do it?
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class MyClass
{
  private:
    string *key;
    string *val;

  public:
    MyClass(int s)
    {
      key = new string[s];
      val = new string[s];
    }
    ~MyClass(int s)
    {
      delete[] key;
      delete[] val;
    }

}
Topic archived. No new replies allowed.