【发布时间】:2021-04-21 18:53:38
【问题描述】:
#include <iostream>
using namespace std;
struct Pos {
int x;
float y;
};
typedef int Pos::* pointer_to_pos_x;
//using pointer_to_pos_x = ???;
int main()
{
Pos pos;
pointer_to_pos_x a = &Pos::x;
pos.*a = 100;
cout << pos.x << endl;
}
在这种情况下我可以使用using 代替typedef 吗?
我在网上搜索了一些资料:有人说using可以替换typedef,但是这个怎么替换呢? (任何文档或博客也会有所帮助。)
【问题讨论】:
-
using pointer_to_pos_x = int Pos::* -
using 与 typedef 相同,但类型倒序。我更喜欢使用它,因为它具有与任何其他分配一样“自然”的顺序和语法。