expected constructor, destructor, or type conversion before '(' token

Hi All,

Im trying to declare the members of an element within my class * object[20]. Here is a sample of the code. But I cant seem to get the context right...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class ProductCode{
    public:
        ProductCode(char code[]);
};

class ProductLine{
    public:
        ProductLine();                                                          
        ProductLine(ProductCode pc, double rrp, double sp,
                int oh, char* desc);
        ~ProductLine();
}

class Inventory{
    private:
        static ProductLine * products[];
};


ProductLine * Inventory::products[20];

Inventory::products[0].pc = "B1111";
Inventory::products[0].rrp= 12.00;
Inventory::products[0].sp= 7.59;
Inventory::products[0].oh= 125;
Inventory::products[0].desc= "SerialNumber5";


Obviously there are some functions and members missing for productLine, but should be enough info to debug. Could someone help? Am i missing something?

Error at line 22

Thanks!
Sekops
1) You need to declare the size of the products array in the class. As a general rule, you can never have empty brackets. About the only exception is when passing as a function parameter.

1
2
3
static ProductLine * products[];   // bad

static ProductLine * products[20];  // good 



2) products is an array of pointers. This means products[0] is a pointer, which means products[0].pc makes no sense. You probably meant products[0]->pc


3) Do you ever actually have the pointers point to something? Setting products[0] like you're doing will only work if they point to an existing object. Are you sure those are supposed to be pointers?
Topic archived. No new replies allowed.