首页 > 解决方案 > Just default values for a struct, or is this doing something else?

问题描述

I recently ran into some code on a project in an early stage in development. It looks like it's setting default values for a struct, but it's not in any way what I'm used to seeing.

It's not "type name = defaultValue". Instead, it looks more like this...but even then not quite.

It almost looks like a merge of the two. It doesn't seem to complain on compilation aside from warnings...but it baffles me.

struct Point
    {
      Point(double _x = 0, double _y = 0, double _z = 0) :
        x(_x),
        y(_y),
        z(_z) {};
      double x, y, z;
    };

typedef Point Vector;

The typedef also seems suspicious, as it makes relative sense to say "whenever I say point, really underneath it's a vector", but the other way around is...odd. I can only imagine the confusion if someone intended to make a vector but got a point instead.

It's also possible that I did not post enough info for this to be discussed. If so, it'll be another day or so before I can add more details.

标签: c++struct

解决方案


推荐阅读