pointer with array

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
#include <cstdlib>
#include <iostream>

using namespace std;
int LEN = 10;
int j = 0;
int k = 0;
//////////////////////////////////////////
class parray
{
      private:
              int* ap[];
              public:
                    parray()
                    { ap[LEN]; }
              void operator [] (int boyut)
              {  
                   ap[boyut];
                   for(int i = 0; i<boyut; i++)
                     *(ap+i) = new int[10];
                     }
              int operator [] (int z)
               {
                  for(j = 0; j < z; j++)
                    for(k = 0; k < z; k++)
                       *(*(ap+j)+k) = 10*k ;
                        return ap[j][k];
                  }
};  
               
               
                                   
int main(int argc, char *argv[])
{ 
    int* ap[LEN];
    
    
  for(int i = 0; i < LEN; i++)
    *(ap+i) = new int[10];
        
   
    for(int j = 0; j < LEN; j++)
      for(int k = 0; k < LEN; k++)
       *(*(ap+j)+k) = 10*k ;
       
       
       for(int j = 0; j < LEN; j++)
         for(int k = 0; k < LEN; k++)
           cout << ap[j][k] << endl;
      
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

hi.I take this error " `int parray::operator[](int)' and `void parray::operator[](int)' cannot be overloaded "
parray have a problem I know this.but i want to for example


parray pa[10];
for(int i = 0; i<LEN; i++)
cout<<pa[i]<<endl;

etc...main program is working but i want to make with class and [] operator.thank u.

You can't overload on the return type. You'll have to rename one of these:

1
2
void operator [] (int boyut)
int operator [] (int z)
thanks.I'am trying
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
#include <cstdlib>
#include <iostream>

using namespace std;
int LEN = 10;
int j = 0;
int k = 0;
//////////////////////////////////////////
class parray
{
      private:
              int* ap[];
              public:
                    parray()
                    { ap[LEN]; }
                    parray(int n) 
                      {
                           for(int i = 0; i < n; i++)
                              *(ap+i) = new int[10];
                                }
                  
             
              
              int operator [] (int z)
               {
                  for(j = 0; j < z; j++)
                    for(k = 0; k < z; k++)
                       *(*(ap+j)+k) = 10*k ;
                        return ap[j][k];
                  }
};  
               
               
                                   
int main(int argc, char *argv[])
{ 
    int* ap[LEN];
    parray fer(10);
    
  for(int i = 0; i < LEN; i++)
    *(ap+i) = new int[10];
        
   
    for(int j = 0; j < LEN; j++)
      for(int k = 0; k < LEN; k++)
       *(*(ap+j)+k) = 10*k ;
       
       
       for(int j = 0; j < LEN; j++)
         for(int k = 0; k < LEN; k++)
           cout << ap[j][k] << endl;
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

omg.it's doesn't working.I take runtime error now.
Line 15 does nothing at all.

That is why it dies.
thanks
Topic archived. No new replies allowed.