I am trying to remove some confusion with a pointer to structures that are used as members of a class. I wrote the following code, but even though the program compiles its failure. Could you tell me what I am doing wrong in the following code?
#include<stdio.h>
#include<string.h>
struct a{
int s;
int b;
char*h;
};
class test
{
public:
a * f;
void dh();
void dt();
};
void test::dh()
{
a d;
d.s=1;
d.b=2;
d.h="ffdf";
f=&d;
}
void test::dt()
{
printf("%s %d %d",f->h,f->b,f->s);
}
int main()
{
test g;
g.dh();
g.dt();
return 0;
}
source
share