Struct with one member or just typedef

c++, struct, typedef

Solution

There's a huge difference. With the typedef all the following are valid:

Y y = 14.3;
y += 7;
y = 1 + y << 3;
std::cout << y;
double d = y;

With the struct none are, unless you choose to expose those operations. The question is, do you have something that is an `int`, with no restrictions, or an abstraction that is in some way based on an integer value, and has its own constraints or invariant?

Problem

While im coding I declare structs or classes because they are based on real world objects/ideas/concepts. But often those structs/classes only have one single member. So I was wondering if it makes any difference, if I simpy make a typedef. And then I'm not sure if that's correct, because typedefs are not 'objects' in my opinion. So should I do: ``` struct Y { int x; } ``` or just: ``` typedef int Y; ``` Does it make any difference? Is my image of structs being objects and typedefs being something else correct?

Original source