Defining an array using classes.

I'm specifically trying to define an array in the header file.
However since I want the user to define the array size, the size I want to define the array I want is undefined in the header when I first declare it.
That gives an error on my IDE "Invalid use of non-static data member".

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #ifndef __Array__salesperson__
#define __Array__salesperson__

#include <stdio.h>
#include <iostream>
#include <array>

#endif /* defined(__Array__salesperson__) */


class Salaryclass
{
public:
    Salaryclass();
    void promptuser();
    int calculatesalary(int &);
private:
    int numberofworkers;
    int salary;
    std::array <int, numberofworkers> workersarray; /* <--- There's an error here */
};

std::array can only have a fixed size known at compile time. Use std::vector if you want to set the size at run time.
Topic archived. No new replies allowed.