-3

I have this following code:

#include "stdafx.h"
#include<iostream>
using namespace std;

const int x = 5;
bool graf_adj[x][x] = {
0,1,1,1,0,
1,0,1,0,0,
1,1,0,1,1,
1,0,1,0,0,
0,0,1,0,0
};
struct Graf
{
    bool adj[x][x];
    char n;
};

int main(){
Graf graf1;
graf1.adj = graf_adj;
}

in main function when i try to assing graf_adj to graf1.adj graf1.adj = graf_adj; complier gives me this error:

Error Expression must be a modifiable lvalue

Can anybody give a solution to this ?

Thank you

Nisan Coşkun
  • 516
  • 7
  • 15

1 Answers1

0

Now that you have added the type for the const:

Here is the solution using memcpy

#include<iostream>
#include <cstring>
const int x = 5;
bool graf_adj[x][x] = {
0,1,1,1,0,
1,0,1,0,0,
1,1,0,1,1,
1,0,1,0,0,
0,0,1,0,0
};
struct Graf
{
    bool adj[x][x];
    char n;
};

int main(){
Graf graf1;
std::memcpy(&graf1.adj, &graf_adj, sizeof(graf1.adj));
}
Ed Heal
  • 59,252
  • 17
  • 87
  • 127