D
Dhoom@Rock
hello i get debug error when i going to overload [] operator..
i compile the program in VC++ 6.0 and get error DEMAGE: aftr normal
block(#51)..
my program get run and also get output but at the end of clossing
brecket i got this error...
My Program:
include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#define LIST 10
class array
{
char *str
i compile the program in VC++ 6.0 and get error DEMAGE: aftr normal
block(#51)..
my program get run and also get output but at the end of clossing
brecket i got this error...
My Program:
include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#define LIST 10
class array
{
char *str
- ;
int a- ;
int b;
public:
array()
{
for(int i=0;i<LIST;i++)
{
str=NULL;
a=0;
}
b=0;
}
~array()
{
for(int i=0;i<b;i++)
delete str;
}
int & operator [] (char * st)
{
b++;
for(int i=0;i<b;i++)
{
if(str!=NULL)
if(strcmp(str,st)==0)return a;
}
if((str = (char *)malloc(sizeof(st)))==NULL)
cout<<"allocation error\n";
strcpy(str,st);
return a;
}
};
main()
{
array a;
int b;
a["dharmesh"] = 10;
a["manish"]=20;
a["dha"]=30;
b=a["dha"];
printf("%d",b);
b=a["dharmesh"];
printf("%d",b);
}
- ;