Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain this C++ syntax? [duplicate]

Tags:

c++

I'm going through someone else's code and came across the following syntax:

typedef struct abc {

   abc() : member(0){}

   unsigned int member

}

It seems like a class with member variable and a constructor, except it is declared struct. I have two questions here.

  1. Is this syntax supported in C?
  2. What would be a reason to use structs over classes?

Thanks a lot in advance.

PS: how do I format the code?

like image 629
dustin ledezma Avatar asked Dec 09 '25 10:12

dustin ledezma


1 Answers

This is not valid C.

In C++, struct and class are essentially synonyms. The only difference is that members and inheritance are public by default in a struct, and private by default in a class.

There are no hard guidelines on whether to choose struct or class. However, you'll often find people using struct only for simple C-like plain old data structures ("PODs").

like image 92
Oliver Charlesworth Avatar answered Dec 11 '25 23:12

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!