A
A
avion2019-02-19 22:50:51
C++ / C#
avion, 2019-02-19 22:50:51

Array of structures in c++?

Hello, how to fill an array of structures if the index is of a different type?

void func_init (struct autom arr[], const int v ) {
    for (int i = 0; i < v; i++) {
        arr[i].so = false;
    }
}

Displays an error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@pestunov, 2019-02-24
_

Here is the working code (no errors)

#include <iostream>
#include <string>
using namespace std;

struct autom {
  bool so;
};

void func_init(struct autom arr[], const int v) {
  for (int i = 0; i < v; i++) {
    arr[i].so = false;
  }
}

int main() {
  
  const int v = 10;
  autom mas[v];
  func_init(mas, v);

  for (int i = 0; i < v; i++) {
    cout << mas[i].so;
  }
  
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question