Недопустимые типы операндов при перегрузке оператора ⇐ C++
Недопустимые типы операндов при перегрузке оператора
I wrote a namespace for linear algebra in C++, in which I have defined a class for Matrix. While overloading operators, I am getting a no match error for operator>> . I have declared the input operator as friend in the matrix class.
I have declared the input operator as friend. As the input operator is not a member function of the class, I have made it a template function for typename U.
LinearAlgebra.h
#include #include #include namespace LinearAlgebra { template class Matrix { private: long long int rows, cols; std::vector arr; public: Matrix(long long int rows, long long int cols); bool isEqual(const Matrix& M1, const Matrix& M2); template friend std::istream& operator(std::istream& input, Matrix& M) { input >> M.rows; input >> M.cols; for (long long int i = 0; i < M.rows; i++) { for (long long int j = 0; j < M.cols; j++) { input >> M.arr[j]; } } return input; } } // namespace LinearAlgebra main.cpp
#pragma once #include #include "LinAlg.h" int main(){ LinearAlgebra::Matrix M(3,3); std::cin >> M; return 0; } The error message is : error: no match for 'operator>>'
Источник: https://stackoverflow.com/questions/780 ... verloading
I wrote a namespace for linear algebra in C++, in which I have defined a class for Matrix. While overloading operators, I am getting a no match error for operator>> . I have declared the input operator as friend in the matrix class.
I have declared the input operator as friend. As the input operator is not a member function of the class, I have made it a template function for typename U.
LinearAlgebra.h
#include #include #include namespace LinearAlgebra { template class Matrix { private: long long int rows, cols; std::vector arr; public: Matrix(long long int rows, long long int cols); bool isEqual(const Matrix& M1, const Matrix& M2); template friend std::istream& operator(std::istream& input, Matrix& M) { input >> M.rows; input >> M.cols; for (long long int i = 0; i < M.rows; i++) { for (long long int j = 0; j < M.cols; j++) { input >> M.arr[j]; } } return input; } } // namespace LinearAlgebra main.cpp
#pragma once #include #include "LinAlg.h" int main(){ LinearAlgebra::Matrix M(3,3); std::cin >> M; return 0; } The error message is : error: no match for 'operator>>'
Источник: https://stackoverflow.com/questions/780 ... verloading
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как вызвать функцию-член родительской структуры при перегрузке оператора дочерней структуры
Anonymous » » в форуме C++ - 0 Ответы
- 45 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вызвать функцию-член родительской структуры при перегрузке оператора дочерней структуры
Anonymous » » в форуме C++ - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Где разместить логику равенства в перегрузке оператора Equals(Tother) или ==? [закрыто]
Anonymous » » в форуме C# - 0 Ответы
- 23 Просмотры
-
Последнее сообщение Anonymous
-