initializing an array in a constructor

Nov 15, 2015 at 11:18pm
I am supposed to make a default constructor that initializes the sectors to be empty, and sets the width to 10... but I'm not sure about how to do the syntax for an array in a class constructor because what I've got isn't working. I've been trying to look up how to do it for a while but the answers are either too complex for the scope of my class or not very helpful so if anyone could help me out with this it would really be appreciated.



1
2
3
4
5
6
7
8
9
class Road
{
  public:
    static const int MAX_WIDTH=15;
    Road(int wdth=10, char sectors[]) : width(wdth) {for (int i = 0; i <= (width - 1); i++) (* this).sectors[i] = ' '; }
  private:
    int width;
    char sectors[MAX_WIDTH];
};
Topic archived. No new replies allowed.