Недопустимые типы операндов при перегрузке оператораC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Недопустимые типы операндов при перегрузке оператора

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»