C ,表达必须是可修改的LVALUE
C++, expression must be a modifiable lvalue
我有以下代码:
#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;
}
当我尝试将graf_adj与graf1.adj串起时,在主要功能中 graf1.adj = graf_adj;
complier给我这个错误:
错误表达式必须是可修改的lvalue
任何人都可以解决这个问题吗?
谢谢
现在您添加了const的类型:
这是使用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));
}
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 对RValue对象调用的LValue ref限定成员函数
- 独立读取-修改-写入顺序
- 当系统的卷被修改时,如何修改WASAPI环回捕获卷
- 修改函数中的指针(将另一个指针作为参数传递)
- 为什么我可以通过引用修改常量返回
- 对于结构,表达式必须是可修改的ivalue
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 为什么不能修改对象中的值?另外,我如何改进此链表?
- 修改创建帐户程序
- 我应该如何修改此代码以使用给定字符串中的字母打印菱形图案
- 如何从子成员函数修改父公共成员变量
- 修改 VS Code 中的默认C++代码段
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- 如何使用递归打印修改后的星号三角形图案
- C ,表达必须是可修改的LVALUE
- 表达式必须是可修改的lvalue:`(x,y)= 0;`
- 将值分配给指针时:表达式必须是可修改的lvalue
- 错误:表达式必须是可修改的LVALUE
- 通过使用模板类,表达式必须是可修改的LVALUE