![]() |
Static objects
Code:
#include<iostream>is not allowed.............but when I put static Such as Code:
#include<iostream>sizeof(A); and the same 8 also in cout << sizeof(allo); Can somebody throw some light on the behavior of static object in its own class. |
Re: Static objects
When its non static you are creating a cycle where the object has an object within itself as a member which is practically impossible to have but when it becomes static its equivalent to global object and so compiler does not give any error.
|
Re: Static objects
I'll add one thing that,-
just declare the class as:- class A { int a,b; A *obj; }; Your problem will be solved. Otherwise, it becomes a recursive definition, which is not allowed. You can surely have a self-referencing pointer. |
| All times are GMT +5.5. The time now is 05:58. |