Differences between struct in C and C++

后端 未结 5 2201
鱼传尺愫
鱼传尺愫 2020-12-20 11:55

I am trying to convert a C++ struct to C but keep getting "undeclared identifier"? Does C++ have a different syntax for referring to structs?

struc         


        
5条回答
  •  梦毁少年i
    2020-12-20 12:23

    You could/should typedef the struct so that you don't need the struct keyword every time you will declare a variable of that type.

    typedef struct _KEY_STATE 
    {
        bool kSHIFT; //if the shift key is pressed 
        bool kCAPSLOCK; //if the caps lock key is pressed down
        bool kCTRL; //if the control key is pressed down
        bool kALT; //if the alt key is pressed down
    } KEY_STATE;
    

    Now you can do:

    KEY_STATE kState;
    

    or (as in the example you have) :

    struct KEY_STATE kState;
    

提交回复
热议问题