Dec 10, 2013 at 8:07am UTC
I had to create an array of 16*16 and initialize with values in class
unsigned int* sub_arr[16][16];
sub_arr[0][0] = 0x63;
sub_arr[0][1] = 0x7C;
sub_arr[0][2] = 0x77;
sub_arr[0][3] = 0x7B;
sub_arr[0][4] = 0xF2;
sub_arr[0][5] = 0x6B;
sub_arr[0][6] = 0x6F;
sub_arr[0][7] = 0xC5;
sub_arr[0][8] = 0x30;
sub_arr[0][9] = 0x01;
sub_arr[0][10] = 0x67;
Errors :ISO C++ forbids declaration of ‘sub_arr’ with no type
../design/hci_top.cpp:58: error: ISO C++ forbids initialization of member ‘sub_arr’
../design/hci_top.cpp:58: error: making ‘sub_arr’ static
../design/hci_top.cpp:58: error: invalid in-class initialization of static data member of non-integral type ‘int [0][0]’
is it possible to create array like above as it is static and class is dynamic?
then what is alternate of creating memory locations of 16*16 and initialised with values?
Regards
cam
Last edited on Dec 10, 2013 at 8:08am UTC
Dec 10, 2013 at 8:27am UTC
all initialization should be done in constructor
Dec 10, 2013 at 9:49am UTC
What is the value of x, as i want its value from 0 .....15. Please throw some more light.
class Example
{
public:
unsigned int sub_arr[16][16]
{
// sub_arr[0][x]
{
0x63, 0x7C, 0x77, 0x7B,
0xF2, 0x6B, 0x6F, 0xC5,
0x30, 0x01, 0x67, 0x56
}
//sub_arr[1][x]
{
0x63, 0x7C, 0x77, 0x7B,
0xF2, 0x6B, 0x6F, 0xC5,
0x30, 0x01, 0x67, 0x56
}
// sub_arr[2][x] ...
};
};
#include <iostream>
int main()
{
Example e;
std::cout << std::hex << e.sub_arr[0][2] << std::endl;
}
My code like below, which i had to develop now, So i had to write 16 times as done in previous reply?
unsigned int sub_arr [16][16];
sub_arr[0][0] = 0x63;
sub_arr[0][1] = 0x7C;
sub_arr[0][2] = 0x77;
sub_arr[0][3] = 0x7B;
sub_arr[0][4] = 0xF2;
sub_arr[0][5] = 0x6B;
sub_arr[0][6] = 0x6F;
sub_arr[0][7] = 0xC5;
sub_arr[0][8] = 0x30;
sub_arr[0][9] = 0x01;
sub_arr[0][10] = 0x67;
sub_arr[0][11] = 0x2B;
sub_arr[0][12] = 0xFE;
sub_arr[0][13] = 0xD7;
sub_arr[0][14] = 0xAB;
sub_arr[0][15] = 0x76;
sub_arr[1][0] = 0xCA;
sub_arr[1][1] = 0x82;
sub_arr[1][2] = 0xC9;
sub_arr[1][3] = 0x7D;
sub_arr[1][4] = 0xFA;
sub_arr[1][5] = 0x59;
sub_arr[1][6] = 0x47;
sub_arr[1][7] = 0xF0;
sub_arr[1][8] = 0xAD;
sub_arr[1][9] = 0xD4;
sub_arr[1][10] = 0XA2;
sub_arr[1][11] = 0xAF;
sub_arr[1][12] = 0x9C;
sub_arr[1][13] = 0xA4;
sub_arr[1][14] = 0x72;
sub_arr[1][15] = 0xC0;
:
:
up to
sub_arr[15][15] = 0xC0;
Last edited on Dec 10, 2013 at 9:51am UTC
Dec 10, 2013 at 10:11am UTC
I wrote
x to help you understand that we're filling one
line row of the matrix at a time.
I also used your own values to make it easy to see.
Here's a simpler example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int matrix[2][3];
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[0][2] = 3;
matrix[1][0] = 4;
matrix[1][1] = 5;
matrix[1][2] = 6;
// equivalent to
int matrix[2][3] {
{1, 2, 3},
{4, 5, 6}
};
Last edited on Dec 10, 2013 at 10:12am UTC
Dec 10, 2013 at 11:21am UTC
thanks catfish666,
I had done as below in class
unsigned int sub_arr[2][16]
{
{0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76},
{0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76}
};
error : function definition does not declare parameters
Is there something i had to do initialization in constructor?
Last edited on Dec 10, 2013 at 11:27am UTC
Dec 10, 2013 at 11:44am UTC
Please post the entire source code, and also put it in code tags:
[co de] int i=0; // example
[/co de]
Please remember that this is a C++11 feature.
If your compiler is not new enough, it may not work. You need to use GCC 4.8+ or Visual Studio 2013.
Dec 10, 2013 at 11:55am UTC
k, then in old gcc versions, How it would be implemented
Dec 10, 2013 at 12:20pm UTC
Last edited on Dec 10, 2013 at 12:20pm UTC