C
codefixer
Hi,
I don't seem to understand why the constructor is never called.
It compiles fine and executes fine....
Thanks.
"calloc_t.h"
class foo
{
int bar[1024];
public:
foo::foo(){ cout << "\n Cosntructing foo....";}
~foo(){ cout << "\n destructing foo....";}
void insert(int);
int get(int) const;
};
void foo::insert(int temp)
{
this->bar[temp]=temp;
}
int foo::get(int temp) const
{
// cout << "\n Value = " << this->bar[temp];
return(this->bar[temp]);
}
int main ()
{
int i,n,j;
foo *ptr_foo;
i = 1024;
ptr_foo = (foo*) calloc (i,sizeof(foo));
if (ptr_foo==NULL)
{
cout << "\n Calloc failed";
exit (1);
}
for (i=0;i<1024;i++)
{
for (j=0;j<1024;j++)
{
ptr_foo.insert(j);
}
}
I don't seem to understand why the constructor is never called.
It compiles fine and executes fine....
Thanks.
"calloc_t.h"
class foo
{
int bar[1024];
public:
foo::foo(){ cout << "\n Cosntructing foo....";}
~foo(){ cout << "\n destructing foo....";}
void insert(int);
int get(int) const;
};
void foo::insert(int temp)
{
this->bar[temp]=temp;
}
int foo::get(int temp) const
{
// cout << "\n Value = " << this->bar[temp];
return(this->bar[temp]);
}
int main ()
{
int i,n,j;
foo *ptr_foo;
i = 1024;
ptr_foo = (foo*) calloc (i,sizeof(foo));
if (ptr_foo==NULL)
{
cout << "\n Calloc failed";
exit (1);
}
for (i=0;i<1024;i++)
{
for (j=0;j<1024;j++)
{
ptr_foo.insert(j);
}
}