S
subramanian100in
Consider the following:
Class Test
{
public:
Test(Test_int arg) : val(arg) { }
typedef int Test_int;
private:
Test_int val;
};
This has an error viz, the typedef for Test_int appears
after its usage. But the compiler won't give any error
for using the data member 'val' in the ctor initializer
when the declaration of 'val' data member appears
later.
Both the typedef declaration and data member
declaration appear inside the class only.
My question is: why does the compiler give an error
for using a typedef name when its declaration appears
later whereas the compiler doesn't give an error when a
data member is used when its declaration appears
later ?
Kindly clarify.
Thanks
V.Subramanian
Class Test
{
public:
Test(Test_int arg) : val(arg) { }
typedef int Test_int;
private:
Test_int val;
};
This has an error viz, the typedef for Test_int appears
after its usage. But the compiler won't give any error
for using the data member 'val' in the ctor initializer
when the declaration of 'val' data member appears
later.
Both the typedef declaration and data member
declaration appear inside the class only.
My question is: why does the compiler give an error
for using a typedef name when its declaration appears
later whereas the compiler doesn't give an error when a
data member is used when its declaration appears
later ?
Kindly clarify.
Thanks
V.Subramanian