문제가 있습니다. 사용자 정의 함수 operator*
을 구현했습니다.C++ 연산자가 오버로드되어 다른 연산자가 표시되지 않습니다.
:
class Matrix
{
public:
Matrix operator*(int arg); //(1)
...
}
Matrix operator*(int a, const Matrix& m)
{
return m * a; //(2)
}
(1) 내가 MAIN.CPP이 작업을 수행 할 수 있습니다
Matrix a = Matrix::GetRandom.....
Matrix b = a * 2;
(2)이 라인에서 내가 갖는 컴파일러 오류 :
를IntelliSense: no operator "*" matches these operandsnoperand types are: const Matrix * int
어떻게 수정합니까?
또한 (비회원) 친구 기능 '친구 매트릭스 연산자 (매트릭스, INT) 등 모두 연산자를 쓸 수를' . 이것은 대칭을 유지하며 서로 옆에 선언됩니다. – dyp