Y
ypjofficial
Pls look at this code
////////////////////start///////////
class a
{
public:
a(){
cout<<"inside constructor of a"<<endl;
}
int b()
{
int i=90;
return i;
}
};
a aa;//creating global object of a;
//confusion 1
aa.b();//this will give an compile error
int i = aa.b();//but this will work fine.
void main()
{
}
//////////code ended/////////////
The confusion is
after i create a global object, i can't call globally any of its
function in the standalone expression.Like aa.b();
but the next statement will work fine.(int i = aa.b()
Why the compiler is behaving like this?
What is the rule here which the compiler is following.?
Thanks and Regards,
Yogesh Joshi.
////////////////////start///////////
class a
{
public:
a(){
cout<<"inside constructor of a"<<endl;
}
int b()
{
int i=90;
return i;
}
};
a aa;//creating global object of a;
//confusion 1
aa.b();//this will give an compile error
int i = aa.b();//but this will work fine.
void main()
{
}
//////////code ended/////////////
The confusion is
after i create a global object, i can't call globally any of its
function in the standalone expression.Like aa.b();
but the next statement will work fine.(int i = aa.b()
Why the compiler is behaving like this?
What is the rule here which the compiler is following.?
Thanks and Regards,
Yogesh Joshi.