chhc0505   2년 전

안녕하세요 코드 31 번 줄에 계속 컴파일 오류가 떠서 질문드립니다.

2차원 vector를 이용해서 matrix를 구현하고 operator *를 만들어서 행렬의 곱을 표현하려했는데 

계속 temp*temp*a 부분에서 컴파일 오류가 뜹니다 ㅠ temp*temp 의 *연산이 끝나면 matrix 객체를 반환하고 그 객체와

a를 * 연산하는게 어떤 문제가 있는건지 잘 모르겠습니다 ..  도와주세요 ! 


다음은 백준의 c++ 컴파일러 기준 컴파일 오류 내용입니다.

error: no match for ‘operator*’ (operand types are ‘matrix’ {aka ‘std::vector<std::vector<long long int> >’} and ‘matrix’ {aka ‘std::vector<std::vector<long long int> >’})

!error: cannot bind non-const lvalue reference of type ‘matrix&’ {aka ‘std::vector<std::vector<long long int> >&’} to an rvalue of type ‘matrix’ {aka ‘std::vector<std::vector<long long int> >’}


긴 글 읽어주셔서 감사합니다

protarie   2년 전

const matrix&로 하면 될 것 같습니다.

해당 오류는 rvalue는 참조로 받을 수 없다는 뜻인데, const참조는 가능할겁니다.

chhc0505   2년 전

정말 감사합니다 ㅠㅠ 

operator 인자 받는 부분을 const Matrix & 로 고치니까 정상적으로 컴파일되네요 ㅠㅠ 감사합니다 !

혹시 컴파일 오류 이유는 temp*temp 로 생긴 matrix 임시 객체는 rvalue여서 참조할 수 없다로 이해해도 될까요 ??

const 붙이니까 오류가 나지 않는 것도 신기하네요.. 

chhc0505   2년 전

넵 ! 답변 정말 감사합니다 ~

댓글을 작성하려면 로그인해야 합니다.