K
K
keldish2016-10-25 22:06:24
C++ / C#
keldish, 2016-10-25 22:06:24

How to assign a value to an array (c++)?

typedef byte tAbc[2][2];
typedef tAbc tAbcs[3][3];
tAbcs* Abc;
void .....
Abc = {{{0,1},{1,1},{1,0}},{{....},{....},{....} },{{....},{....},{....}}}
what is wrong, tell me
cannot convert '' to 'byte (*)[3][3][2][ 2] {aka unsigned char (*)[3][3][2][2]}' in assignment

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Zhilin, 2016-10-25
@Anton3

  1. You are assigning the value of an array to a pointer to an array. This is the same as int* p = 42;.
    The compiler needs a memory area where the array itself will be stored. That is, at least it should betAbcs Abc;
  2. As far as I know, in C++ you can only initialize arrays this way, not copy/assign. If you want assignment to work the way you do, use std::array.

F
Fil, 2016-10-25
@Fil

You are trying to assign values ​​to a pointer using aggregate initialization . Also, you have lost one dimension, which will lead to filling part of the array with zeros.

tAbcs Abc =
  {
    { { { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } } },
    { { { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } } },
    { { { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 } } },
  };

K
keldish, 2016-10-25
@keldish

I know about the dimension, this is an example for describing my problem,
I know how to do it in pascal, but I also need to write it in c++, for Arduino.
type
tabc=array[1..2, 1..2] of byte;
tabcs=array[1..3,1..3] of tabc;
varabcs:^tabcs;
how to implement it in c++ and assign values ​​to this array?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question