problem with array into function

Hello i'm new to C++ programming,and i have an error with the follown code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
   void operator<<(float **p,array ar){
        int i,j;
        p=(float **)malloc(ar.n*sizeof(float*));//grammes

        for(i=0;i<ar.n;i++){
           p[i]=(float *)malloc(ar.m*sizeof(float));//sthles

           }
        for(i=0;i<ar.n;i++){
               for(j=0;j<ar.m;j++){
                       p[i][j]=ar.a[i][j];
                       }
                       }                                           
        };


array is a type defined by the following class:

1
2
3
4
5
6
7
8
9
10
11
12
class array {
      int n,m;
      float **a;
      public:
      array operator()(int r,int c);
      array operator~();
      array operator*(array ap);
      array operator=(array ap);
      void operator++();
      void operator!();
      friend void operator<<(float **p,array ar);    
      };



i am supposed to call this operator with an expression like p<<ar , and the array from the object "ar" must be saved in this pointer..However,in the main function,this doesn't seem to happen,and the programm crashes whenever i try to print a value from the array p,but in the function everything is ok (i can print a value from p)..please help..thank you.
in the function, p is a copy of the variable in main. when you change p, the variable in main doesn't change. float**& should work.
by the way, http://www.cplusplus.com/forum/articles/17108/
Thank you..it seems to work now(it doesn't crash but it shows "rubish",some logical fault that i'll find)..And thanks for the topic about MD..It'll help me a lot,since our teacher never actually explained as in detail all about arrays...Thanks again :)
Topic archived. No new replies allowed.