本文介绍了在C ++ 11中提出的无限制联合是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收集无限制联盟
作为在C ++ 11中提出的功能之一。任何人都可以解释这个背后的语义和它提供的优势吗?
I gather unrestricted unions
as one of the functionality being put forth in C++11. Can anyone please explain the semantics behind this and the advantages it provides?
推荐答案
维基百科上有一个解释:
There is an explaination on Wikipedia : http://en.wikipedia.org/wiki/C%2B%2B0x#Unrestricted_unions
先搜索询问C ++ 0x功能说明。
Search there first before asking about C++0x features explainations.
无限制联盟
//for placement new
#include <new>
struct Point {
Point() {}
Point(int x, int y): x_(x), y_(y) {}
int x_, y_;
};
union U {
int z;
double w;
Point p; // Illegal in C++; point has a non-trivial constructor.
// However, this is legal in C++0x.
U() { new( &p ) Point(); } // No nontrivial member functions are
//implicitly defined for a union;
// if required they are instead deleted
// to force a manual definition.
};
更改不会破坏任何
现有代码,因为它们只放松
当前
The changes will not break any existing code since they only relax current rules.
这篇关于在C ++ 11中提出的无限制联合是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!