结构体定义如下:位于.h文件中
struct Node
{
enum Type { Horizontal, Vertical, Leaf };
union {
qreal offset;
int leafIndex;
};
Type type;
};
引用方法,测试为结构体名称+小括号:
Node m_node;
m_node.leafIndex = 1;
//int x = m_node.type.Horizontal;
int xw = m_node.leafIndex;
m_node = Node();
经调试m_node值会被一个新的引用所替代,m_node.leafIndex = 0;
也验证了结构体+()是可以初始一个结构体变量的,但一般的文章并没有给出这种方式,欢迎指正。