Program obiektowy pomocy

0

Witam,
Proszę o pomoc w znalezieniu w kodzie błędu. Prawdopodobne miejsca błędu owinąłem w komentarze.
Pozdrawiam

#include<iostream>
using namespace std;
class array
{ private:
        double *d;
        int len;
public:
        array(int size=0) : d(0),/*len(size)*/                                           //-mozliwy blad
		{ if(size>0)
                {
                        d= new double [size]; for(int i=0;i<len;i++) d[i]=0;
                }
                cout <<"array\n";
        }
        array(const array& a) : d(0)
        {  if(a.len>0)
                {
                        len=a.len;
                        d=new double[a.len]; for(int i=0;i<len;i++)       /*d[i]=a.d[i]*/;      //mozliwy blad
                }
        }

        array& operator=(const array& a)
        { cout <<"=";
                if(a.len>0)
                {
                        if(len>0) delete [] d;
                        d= new double [/*a.len*/]; for(int i=0; i<len; i++) d[i]=a.d[i];       //mozliwy blad
                }
                return  /**this*/;                                                 //mozliwy blad
        }

        ~array()
        {if(len>0) delete [] d; cout <<"\n~array";
        }
        double& operator[](int i)
        { cout<<"["<<i<<"]";
                return d[i];
        }
        ostream& operator<<(ostream & out)
        { for(int i=0; i<len;i++) out<<d[i]<<" ";
        return /*out */  ;                                                   //mozliwy blad
        }
        operator int() {return len;}
};

array g;
int main()
{
        try
        {
                cout<<"main:\n";
                array a(2);
                array b=a;
                double c=a;
                b[0]=3;
                a[1]=4;
                b<<(cout<<a);
				cout<<"\n";
                cout<<b[0]<<" "<<b[1];
                cout<<"\nend";
        } catch(exception e) {}
		system("pause");
        return 0;
}


 
0

mógłbyś napisać konkretnie co Ci nie działa w Twoim programie ??

1 użytkowników online, w tym zalogowanych: 0, gości: 1