S
seema
Hi all,
I am new to C++ programming. Can some body explain how to intialize the
structure values, consider this program,
#include <iostream.h>
struct mystruct
{
int a,b,c,d,e,f;
};
class myclass
{
mystruct x;
public:
myclass(){}
void display(){
cout <<"Hi guys ";
}
};
int main()
{
myclass me;
me.display();
}
If you debug this program in gdb and stop it in display() and see the
values of "x" they all contain some garbage values. I know we have to
intialize the values of struct in the constructor, to over come this
problem, we have to explicitly assign values to each and every
member of your structure like this,
myclass () { x.a=0;x.b=0;x.c=0;x.d=0;x.e=0;x.f=0;} But your code will
become messy when the members of the structure you have to intialize
are huge. Is their any way I can assign zero values to all of the
members of the structure at one shot? I mean any function that can be
used on Linux to do this initialization??
Some body please explain,
Seema Rao
I am new to C++ programming. Can some body explain how to intialize the
structure values, consider this program,
#include <iostream.h>
struct mystruct
{
int a,b,c,d,e,f;
};
class myclass
{
mystruct x;
public:
myclass(){}
void display(){
cout <<"Hi guys ";
}
};
int main()
{
myclass me;
me.display();
}
If you debug this program in gdb and stop it in display() and see the
values of "x" they all contain some garbage values. I know we have to
intialize the values of struct in the constructor, to over come this
problem, we have to explicitly assign values to each and every
member of your structure like this,
myclass () { x.a=0;x.b=0;x.c=0;x.d=0;x.e=0;x.f=0;} But your code will
become messy when the members of the structure you have to intialize
are huge. Is their any way I can assign zero values to all of the
members of the structure at one shot? I mean any function that can be
used on Linux to do this initialization??
Some body please explain,
Seema Rao