P
Pallav singh
Hi ,
I run following program in g++
#include<iostream>
using namespace std;
class A {
int * ptr1;
int * ptr2;
int a;
public:
void print()
{ cout << ptr1 << "\t" << ptr2 << "\t" << a <<endl; }
};
int main()
{
A a;
a.print();
return 0;
}
$ ./a.exe
0 0x22d000 1629643390
++++++++++++++++++++++++++++++++++++++++
IS MY i getting initialized here ?
++++++++++++++++++++++++++++++++++++++++
FROM C++ programming Language : Bjarne Stroustrup
10.4.2 Default Constructors [class.default]
A compiler generated default constructor implicitly calls the default
Constructors for a class’ members of class type and bases (§12.2.2).
For example:
Struct Tables {
int i;
int vi [10];
Table t1 ;
Table vt [10];
};
Tables tt ;
Here, tt will be initialized using a generated default constructor
that calls Table (15)
for tt.t1 and each element of tt.vt . On the other hand, tt.i and the
elements of tt.vi
are not initialized because those objects are not of a class type. The
reasons for
the dissimilar treatment of classes and builtin types are C
compatibility and fear
of runtime overhead.
Thx
Pallav Singh
I run following program in g++
#include<iostream>
using namespace std;
class A {
int * ptr1;
int * ptr2;
int a;
public:
void print()
{ cout << ptr1 << "\t" << ptr2 << "\t" << a <<endl; }
};
int main()
{
A a;
a.print();
return 0;
}
$ ./a.exe
0 0x22d000 1629643390
++++++++++++++++++++++++++++++++++++++++
IS MY i getting initialized here ?
++++++++++++++++++++++++++++++++++++++++
FROM C++ programming Language : Bjarne Stroustrup
10.4.2 Default Constructors [class.default]
A compiler generated default constructor implicitly calls the default
Constructors for a class’ members of class type and bases (§12.2.2).
For example:
Struct Tables {
int i;
int vi [10];
Table t1 ;
Table vt [10];
};
Tables tt ;
Here, tt will be initialized using a generated default constructor
that calls Table (15)
for tt.t1 and each element of tt.vt . On the other hand, tt.i and the
elements of tt.vi
are not initialized because those objects are not of a class type. The
reasons for
the dissimilar treatment of classes and builtin types are C
compatibility and fear
of runtime overhead.
Thx
Pallav Singh