S
subramanian100in
Consider the program
#include <iostream>
using namespace std;
class Test
{
public:
Test(Test_int c_value)
{
value = c_value;
}
typedef int Test_int;
private:
Test_int value;
};
int main()
{
Test t(100);
return 0;
}
Here I am getting compilation error for the line
Test(Test_int c_value)
because it uses Test_int type which is not known at that point and is
declared afterwards.
If I declare
typedef int Test_int;
before the the ctor, the compilation error goes. But the data member
'value' is used inside the ctor at which point the definition of the
variable is not known(it is defined later in the private section).
My doubt is why the compiler is unable to see the typedef declaration
for Type_int when it occurs later in the class; but it is able to see
the data member 'value' used in the ctor but which is actually defined
inside the private section later in the class.
Why are the typedef and variable definition inside the class treated
differently ?
Kindly explain
Thanks
V.Subramanian
#include <iostream>
using namespace std;
class Test
{
public:
Test(Test_int c_value)
{
value = c_value;
}
typedef int Test_int;
private:
Test_int value;
};
int main()
{
Test t(100);
return 0;
}
Here I am getting compilation error for the line
Test(Test_int c_value)
because it uses Test_int type which is not known at that point and is
declared afterwards.
If I declare
typedef int Test_int;
before the the ctor, the compilation error goes. But the data member
'value' is used inside the ctor at which point the definition of the
variable is not known(it is defined later in the private section).
My doubt is why the compiler is unable to see the typedef declaration
for Type_int when it occurs later in the class; but it is able to see
the data member 'value' used in the ctor but which is actually defined
inside the private section later in the class.
Why are the typedef and variable definition inside the class treated
differently ?
Kindly explain
Thanks
V.Subramanian