#include<iostream.h>
#include<conio.h>
using namespace std;
class Array
{
private:
int* ptr;
int size;
public:
Array() :ptr(0), size(0)
{ }
Array (int s) : size(s)
{ ptr= new int[s]; }
Array(Array&);
~Array()
{ delete[] ptr;}
int& operator [] (int j)
{
return *(ptr+j);
}
Array& operator = (Array&);
};
// ...........................................................................
Array::Array(Array& a)
{
size=a.size;
ptr=new int[size];
for(int j=0; j<size; j++)
*(ptr+j)=*(a.ptr+j) ;
}
Array& Array::operator = (Array& a)
{
delete[] ptr;
size=a.size;
ptr=new int[a.size];
for(int j=0; j<a.size;j++)
*(ptr+j)=*(a.ptr+j);
return *this;
}
////////////////////////////////////////////////
main()
{
const int asize=10;
Array arr1(asize);
for(int j=0; j<=asize; j++)
{arr1[j]=j*j;
cout<< arr1[j]<<" "; }
Array arr2(arr1);
cout<<"\narr2: " ;
for (int j=0; j<asize; j++)
cout<< arr2[j]<< " " << endl ;
Array arr3, arr4;
arr4=arr3=arr1;
cout<<"\narr3: " ;
for (int j=0; j<=asize;j++)
cout<<arr3[j] << " " ;
cout<<"\narr4: " ;
for (int j=0; j<asize; j++)
cout<<arr4[j] << " " ;
// getch();
cout<< endl;
return 0;
getch();
}
Recommended Answers
Jump to PostThe error is in the chair.
The error didn't read "how to post code" threads all over the forum.
The error needs to do better at making a post which is readable.
All 3 Replies
Salem 5,265 Posting Sage
Murtan 317 Practically a Master Poster
noureenjee -6 Newbie Poster
William Hemsworth commented: Oh dear :\ -1
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.