nezvers

C++ init class member in definition

Nov 20th, 2020 (edited)
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. /*
  2. Github: https://github.com/nezvers
  3. Youtube: https://www.youtube.com/channel/UCb4-Y0E6mmwjtawcitIAzKQ
  4. Twitter: https://twitter.com/NeZversStudio
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. class MyClass{
  10. public:
  11.     MyClass(){}
  12.     int var {5};
  13. };
  14.  
  15. typedef struct MyStruct{
  16.     int var {7};
  17. }MyStruct;
  18.  
  19. int main(){
  20.     MyClass c;
  21.     printf("%i \n", c.var);
  22.     MyStruct s;
  23.     printf("%i \n", s.var);
  24.     return 0;
  25. };
Add Comment
Please, Sign In to add comment