Skip to content

Instantly share code, notes, and snippets.

@mathiasose
Last active December 19, 2015 03:29
Show Gist options
  • Save mathiasose/5890485 to your computer and use it in GitHub Desktop.
Save mathiasose/5890485 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Foo {
public:
union {
float arr[3];
struct {
float x,y,z;
};
};
};
int main() {
Foo foo;
foo.x = 1;
foo.y = 2;
foo.z = 3;
cout << foo.arr[0] << foo.arr[1] << foo.arr[2] << endl;
foo.arr[0] = 4;
foo.arr[1] = 5;
foo.arr[2] = 6;
cout << foo.x << foo.y << foo.z << endl;
cout << ( (foo.x == foo.arr[0] && foo.y == foo.arr[1] && foo.z == foo.arr[2]) ? "med en union kan man definere at to like store sett med variables skal referere til samme sett values" : "" ) << endl;
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment