what is wrong here ?

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#include <iostream>

using namespace std;

class myc
{
    int * arr;
  public:
        myc()
        {
            arr = new int[50];
        }

        int& operator[](int i)
        {
            return arr[i];
        }

        ~myc()
        {
            delete arr;
        }
};

class sup
{
    myc * arr;
  public:
        sup()
        {
            arr = new myc[50];
        }

        myc& operator[](int i)
        {
            return arr[i];
        }

        ~sup()
        {
            delete[] arr;
        }
};

int main()
{
    cout << "Hello world!" << endl;

    sup s;

    sup[0][0] = 72;

    cout<< sup[0][0]<<endl;

    return 0;
}




my above code is not compiling (as usual) , i am not understanding what exact error
the message at [][] operator is expected unqualified id before [ token ?
i use codeblocks with gcc compiler on windows
s[0][0] = 72;
thanks , but there is no space in between
1
2
3
4
5
    sup s;

    sup[0][0] = 72;

    cout<< sup[0][0]<<endl;


Your declaring 's' as an object of the sup class. Then instead of using the object of sup, you type sup[0][0] = 72 and use the class. Change that line to s[0][0] = 72 as guest said earlier.
Last edited on
sorry i didn't see it properly .

silly mistake (or i am really fool ? ) , thanks to both of you .
Topic archived. No new replies allowed.