What is the difference between struct and typedef struct in C++?
Hi everyone! I recently started learning C++ after C, and I have a question about declaring structures. In C, I used to write like this:
```c
typedef struct {
int x;
int y;
} Point;
```
And then use `Point` as a regular type. But when I switched to C++, I saw that many people just write:
```cpp
struct Point {
int x;
int y;
};
```
And then use `Point` without `struct`. This confuses me. I tried both variants in C++, and both work. But what is the difference between them? Do I need to use `typedef struct` in C++ at all? Or is it considered bad practice? I heard that in C++ structures are almost like classes, but I'm not sure how this affects the declaration. Can `typedef` somehow affect performance or how the compiler processes the code? I will be
No answers yet.
Log in to leave an answer