I have array of four items: a, a, a, a
I want to assign these four to one int:
no problem to assign two items like
array[ row ][ column ] = id;
is there a possibility to assign four?
testArray[ 0 ][ 0 ] = a;
testArray[ 0 ][ 1 ] = b;
testArray[ 0 ][ 2 ] = c;
testArray[ 0 ][ 3 ] = d;
testArray = id;
If can not use int, we can use any other type as holder...
impetus, can you give an example with real numbers, not 'a', 'b', 'c', 'd', 'id'. Are you trying to individually manipulate each byte of an int separately? Or are you just trying to do some shorthand to assign all inner indices at once?
If you're trying to do type punning, note that C is lenient on this sort of thing, but C++ is (at least, in terms of the standard itself) more strict here. Something like std::copy or memcpy could work as a one-liner.
you can use a block copy like memcpy to move 4 consecutive ints in a 2d array into a working 1d 4 location array. This works for ints and simple things, but its kinda Cish. If that has any relevance to what you wanted.
you can even exploit a 1 byte aligned struct (or whatever words you want for no padding/alignment) to do the same, if you want to name them a,b,c,d.
cout << x.a; //is array[row];
cout << x.b; //array[row];
and so on. Basic C style memory tricks and smoke & mirrors. But its not terribly great idea or great code.
most compilers have a pragma or something to align as you need, or a global setting (the pragmas can get current, change it, restore current back pattern).