[okl4-developer] About C++ Global or Local variable.
Geoffrey Lee
glee at ok-labs.com
Fri Oct 10 03:04:52 EST 2008
On Thu, Oct 09, 2008 at 12:51:42PM +0900, 유호철 wrote:
> Hi all.
>
> I asked about L4 C++ library porting already before.
>
> Since, advanced the rate of progress ( so little...)
>
> At result, I succes c++ compile. c++ code following..........
>
> ----------------------------------------------------
>
> #include <stdlib.h>
> extern "C" void printf(char const*, ...);
> class CRectangle {
> int width, height;
> public:
> CRectangle (int,int);
> int area () {return (width*height);}
> };
> CRectangle::CRectangle (int a, int b) {
> printf("constructor call.\n");
> width = a;
> height = b;
> }
> CRectangle rect1 (4,5);
> int main()
> {
> CRectangle rect2 (3,4);
> printf("rect1 : %d\n", rect1.area());
> printf("rect2 : %d\n", rect2.area());
> return 0;
> }
>
> ----------------------------------------------------
>
> [ execution result ]
>
> rect1 : 0
> constructor call.
> rect2 : 12
>
> -----------------------------------------------------
>
> Local variable rect2 initialize success.
>
> But, Global variable rect1 is not initialization.
Globals will probably need to have their constructors called
at initialization time (in crt0 or similar).
-gl
>
> If I talk differently,
>
> Local variable call constructor in creation.
>
> Bur, Global variable don`t.
>
>
> any thanks in advanced.
> _______________________________________________
> Developer mailing list
> Developer at okl4.org
> https://lists.okl4.org/mailman/listinfo/developer
--
More information about the Developer
mailing list