[okl4-developer] About C++ Global or Local variable.

유호철 hcyoo at cuwave.co.kr
Thu Oct 9 14:51:42 EST 2008


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.

If I talk differently, 

Local variable call constructor in creation. 

Bur, Global variable don`t. 


any  thanks in advanced.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.okl4.org/pipermail/developer/attachments/20081009/4e807f44/attachment.htm 


More information about the Developer mailing list