R
Rahul
Hi Everyone,
I have the following code,
class A
{
public : ~A()
{
printf("in ~A\n");
}
A operator++(int)
{
A obj;
printf("in operator function\n");
return(obj);
}
A()
{
printf("in A\n");
}
};
int main()
{
A obj;
printf("1\n");
obj++;
printf("2\n");
return(0);
}
and the output i get is,
in A
1
in A
in operator function
in ~A // Destructor for local object
in operator function
in ~A // Destructor is invoked for
which object???
2
in ~A
second, is it possible to have the operator++(int) [postfix operator+
+] to return a reference? As per my program it isn't possible as
returning reference of a local variable doesn't make any sense...
Thanks in advance!!!
I have the following code,
class A
{
public : ~A()
{
printf("in ~A\n");
}
A operator++(int)
{
A obj;
printf("in operator function\n");
return(obj);
}
A()
{
printf("in A\n");
}
};
int main()
{
A obj;
printf("1\n");
obj++;
printf("2\n");
return(0);
}
and the output i get is,
in A
1
in A
in operator function
in ~A // Destructor for local object
in operator function
in ~A // Destructor is invoked for
which object???
2
in ~A
second, is it possible to have the operator++(int) [postfix operator+
+] to return a reference? As per my program it isn't possible as
returning reference of a local variable doesn't make any sense...
Thanks in advance!!!