c++ - 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.
解决方案
推荐阅读
- php - 在函数中调用另一个函数 - 定位输出
- php - 几秒钟后执行查询
- json - 在 Athena 中读取不一致的嵌套 JSON
- html - 为什么 flex-wrap:wrap 属性会导致我的 div 大小不均?
- c# - Splunk C# 客户端问题 #1:自定义身份验证令牌标头出错
- laravel - 在 get() 之后执行 where()
- ios - Fastlane Beta:Bundler::GemNotFound:在任何源中都找不到 CFPropertyList-3.0.0
- asp.net-core - 使用标识框架在 Windows 服务中托管 ASP.NET Core
- php - mysqli_query 期望参数 1 是 mysqli AND mysqli_fetch_all 问题
- c - 结果不一致和 pthread 混淆