how to initializing this array
Jun 28, 2011 at 8:49pm UTC
hi bros i have done some operator overloading for New operator of array now look please :
i want to initialize pdArray element to some integer value like from 1 to 10 how can i do it please help me how can i initializing an integer on that type cause compiler give me conversion problem int to another type
here is the code:
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#include <iostream>
#include <conio.h>
using namespace std;
class newarr{
unsigned ByteAloc;
unsigned ByteDel;
unsigned NewCal;
unsigned DelCal;
public :
newarr()
{
ByteAloc=0;
ByteDel=0;
NewCal=0;
DelCal=0;
}
void NewArCalled(size_t size)
{
NewCal++;
ByteAloc+=size;
}
void DelArCalled(size_t size)
{
DelCal++;
ByteDel+=size;
}
~newarr()
{
cout<<"\nbyte Allocated:" <<ByteAloc;
cout<<"\nbyte deled:" <<ByteDel;
cout<<"\nNew Call:" <<NewCal;
cout<<"\ndel Call:" <<DelCal;
}
};
newarr mem;
class SizeAlloc
{
int x;
public :
SizeAlloc(int a)
{
x=a;
}
SizeAlloc()
{
x=0;
}
void *operator new [](size_t size)
{
mem.NewArCalled(size);
return (void *)::new char [size];
}
void operator delete [](void *memi,size_t size)
{
mem.DelArCalled(size);
::delete [] memi;
}
void show()
{
cout<<x;
}
};
int main()
{
int i;
const int arraySize=5;
SizeAlloc *dataArray=new SizeAlloc[arraySize];
SizeAlloc *pdArray[arraySize];
for (int i=0;i<arraySize;i++){
pdArray[i]=new SizeAlloc[i];
delete [] dataArray;
for (i=0;i<arraySize;i++)
delete pdArray;
return 0;
}
Jun 29, 2011 at 4:50pm UTC
nobody can help me?
Jun 29, 2011 at 5:01pm UTC
You need to overload the = operator if you want to assign something in that way.
Jun 29, 2011 at 5:02pm UTC
thanx bro for reply mate can u please show me how?
Jun 29, 2011 at 5:05pm UTC
Topic archived. No new replies allowed.