expression must be a modifiable lvalue with 2D arrays

Hello,
I have an error in the constructor.
Please help me.

Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include<string>
using namespace std;

class MyMatrix
{
private:
	int my[3][3];
public:
	MyMatrix(int s[3][3])
	{
		my = s;
	}
	void operator +(MyMatrix first)
	{

	}

};
int main()
{


	return 0;
}
Hello Shervan360,

I have an error in the constructor.
I have an answer it is 42 https://www.youtube.com/watch?v=aboZctrHfK8

If you are going to keep the actual complete error message to your-self how do you expect an answer.

Just guessing I am thinking that my = s; is not the way to copy an array.

And "my" and "s" very bad names. "my" what is my first question. And what is "s" for?

Andy
my = s can be changed to: memcpy(my,s, sizeof(int)*9); //9 is 3*3.
memcpy will work here, but if you change to ** or objects instead of integers or anything fancy you should use a loop to copy it manually or provide iterators so you can use std::copy.
Last edited on
Topic archived. No new replies allowed.