I am trying to do matrix : multiplication , addition , subtraction and transverse using vector ,set function and get function. i can not understand what is the error i am doing in definition . .h and .cpp files and the list of errors is attached . Can you tell me why are these errors happening and suggesting changes if that's ok ?
Header.h
#pragma once
#include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
class matrix {
vector<vector<int>> matrix::definematrixM(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
matrix matrixM;
if (getColumn(matrix1) != getRow(matrix2))
{
std::cout << "matrix can not be multiplied";
// matrix substraction
vector<vector<int>> matrix:: matrixS(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
int a = matrix1[0].size();
int b = matrix2[0].size();
if ( a > b || a == b)
{
matrixS(matrix1,matrix2)[0].resize(a);
}
else
{
matrixS(matrix1, matrix2)[0].resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c== d)
{
matrixS(matrix1, matrix2).resize(c);
}
else
{
matrixS(matrix1, matrix2).resize(d);
}
//matrix addition
vector<vector<int>> matrix::matrixA(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
vector<vector<int>>matrix5;
int a = matrix1[0].size();
int b = matrix2[0].size();
if (a > b || a== b)
{
matrixA(matrix1,matrix2).resize(a);
}
else
{
matrixA(matrix1,matrix2).resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c == d)
{
matrixA(matrix1,matrix2).resize(c);
}
else
{
matrixA(matrix1,matrix2).resize(d);
}
for (int i = 0;i< matrixA(matrix1,matrix2).size();i++)
for (int j = 0;j < matrixA(matrix1, matrix2)[0].size();j++)
{
matrix5[i][j] = matrix1[i][j] + matrix2[i][j];
}
matrixA(matrix1, matrix2) = matrix5;
return matrixA(matrix1, matrix2);
};
Severity Code Description Project File Line Suppression State
Error C2556 'void matrix::definematrix(int,int)': overloaded function differs only by return type from 'std::vector<std::vector<int,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>> matrix::definematrix(int,int)' Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\header.cpp 16
Error C2371 'matrix::definematrix': redefinition; different basic types Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\header.cpp 15
Error C2371 'matrix::definematrix': redefinition; different basic types Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\header.cpp 15
Error (active) declaration is incompatible with "std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> matrix::definematrix(int definematrixrow, int definematrixcolumn)" (declared at line 15 of
Thanks . I changed it but their is another issue . i wanted to define matrix size using inputted int define row , int define column
vector<vector<int>> definematrix(int definematrixrow, int definematrixcolumn)
{
int matrixcolumn = definematrixcolumn;
int matrixrow = definematrixrow;
=> matrix_shishir(definematrixrow,definematrixcolumn).resize(definematrixrow);
for (int i = 0;i < definematrixcolumn;i++)
matrix_shishir[i].resize(definematrixcolumn);
}
In this line => matrix_shishir : it says : matrix_shishir is undefined . but i defined in the header file . Can you explain ?
i defined a new variable in public as
vector<vector<int>> matrix_shi(int definematrixrow, int definematrixcolumn);
and then
{
int matrixcolumn = definematrixcolumn;
int matrixrow = definematrixrow;
matrix_shi(definematrixrow,definematrixcolumn).resize(definematrixrow);
for (int i = 0;i < definematrixcolumn;i++)
matrix_shi[i].resize(definematrixcolumn);
}
but the error is still there . Should not the error go away if i inputted a new variable : matrix_shi instead of the old one:matrix_shishir ?
It's difficult to tell without context. That call you have there is only valid from the scope of a member function of matrix. Also you're using the member inconsistently, it would seem. matrix_shi(definematrixrow,definematrixcolumn) <-- Function? matrix_shi[i] <-- Or vector?
I changed it like you said .It is the first part of Header.cpp file where i am creating a vector to store the arguments
{
int matrixcolumn = definematrixcolumn;
int matrixrow = definematrixrow;
=>matrix_shi.resize(definematrixrow);
for (int i = 0;i < definematrixcolumn;i++)
matrix_shi[i].resize(definematrixcolumn);
}
I am using resize to create the first row and then using loop function to create columns .It is still showing error . it says " matrix_shi is not defined " . But it is defined in header.h file . This means that even if i change the variable names or use loop function for both row and column, the vector will still not be created . matrix_shi is not used anywhere in the program .So name is not the problem . Can you suggest something ?
Not by just looking at bits and pieces of the code. If you've modified it then please post the entire thing, because I can't tell what I'm looking at.
Also, I'm sick of looking at unformatted code, could you use code tags, please. They're there for a reason.
vector<vector<int>> matrix::definematrixM(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
matrix matrixM;
if (getColumn(matrix1) != getRow(matrix2))
{
std::cout << "matrix can not be multiplied";
// matrix substraction
vector<vector<int>> matrix:: matrixS(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
int a = matrix1[0].size();
int b = matrix2[0].size();
if ( a > b || a == b)
{
matrixS(matrix1,matrix2)[0].resize(a);
}
else
{
matrixS(matrix1, matrix2)[0].resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c== d)
{
matrixS(matrix1, matrix2).resize(c);
}
else
{
matrixS(matrix1, matrix2).resize(d);
}
//matrix addition
vector<vector<int>> matrix::matrixA(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
vector<vector<int>>matrix5;
int a = matrix1[0].size();
int b = matrix2[0].size();
if (a > b || a== b)
{
matrixA(matrix1,matrix2).resize(a);
}
else
{
matrixA(matrix1,matrix2).resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c == d)
{
matrixA(matrix1,matrix2).resize(c);
}
else
{
matrixA(matrix1,matrix2).resize(d);
}
for (int i = 0;i< matrixA(matrix1,matrix2).size();i++)
for (int j = 0;j < matrixA(matrix1, matrix2)[0].size();j++)
{
matrix5[i][j] = matrix1[i][j] + matrix2[i][j];
}
matrixA(matrix1, matrix2) = matrix5;
return matrixA(matrix1, matrix2);
};
[ERRORS]
Severity Code Description Project File Line Suppression State
Error C3861 'matrix_shishir': identifier not found Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 33
Error C2084 function 'void matrix::delmat(std::vector<std::vector<int,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>> *)' already has a body Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\header.cpp 29
Error C2084 function 'void matrix::delmat(std::vector<std::vector<int,std::allocator<_Ty>>,std::allocator<std::vector<_Ty,std::allocator<_Ty>>>> *)' already has a body Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\header.cpp 29
Error (active) identifier "matrix_shishir" is undefined Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 33
Error (active) identifier "matrix_shishir" is undefined Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 43
Error C2065 'matrix_shishir': undeclared identifier Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 43
Error (active) too few arguments in function call Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 48
Error C2660 'matrix::definematrixM': function does not take 0 arguments Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 48
Error (active) too few arguments in function call Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 49
Error C2660 'matrix::matrixA': function does not take 0 arguments Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 49
Error (active) too few arguments in function call Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 50
Error C2660 'matrix::matrixS': function does not take 0 arguments Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 50
Error (active) too few arguments in function call Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 51
Error C2660 'matrix::matrixT': function does not take 0 arguments Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 51
Error (active) too few arguments in function call Project5 c:\Users\chica\Documents\Visual Studio 2015\Projects\Project5\Project5\Source.cpp 53
Hi , the error message i am unable to figure out is :
:Severity Code Description Project File Line Suppression State
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) Project5 c:\users\chica\documents\visual studio 2015\projects\project5\project5\source.cpp 49
Can anybody what's wrong with the code ?
{my code }
[HEADER.H]
#pragma once
#include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
class matrix {
vector<vector<int>> matrix::definematrixM(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
matrix matrixM;
if (getColumn(matrix1) != getRow(matrix2))
{
std::cout << "matrix can not be multiplied";
// matrix substraction
vector<vector<int>> matrix:: matrixS(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
int a = matrix1[0].size();
int b = matrix2[0].size();
if ( a > b || a == b)
{
matrixS(matrix1,matrix2)[0].resize(a);
}
else
{
matrixS(matrix1, matrix2)[0].resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c== d)
{
matrixS(matrix1, matrix2).resize(c);
}
else
{
matrixS(matrix1, matrix2).resize(d);
}
//matrix addition
vector<vector<int>> matrix::matrixA(vector<vector<int>>matrix1, vector<vector<int>>matrix2)
{
vector<vector<int>>matrix5;
int a = matrix1[0].size();
int b = matrix2[0].size();
if (a > b || a== b)
{
matrixA(matrix1,matrix2).resize(a);
}
else
{
matrixA(matrix1,matrix2).resize(b);
}
int c = matrix1.size();
int d = matrix2.size();
if (c > d || c == d)
{
matrixA(matrix1,matrix2).resize(c);
}
else
{
matrixA(matrix1,matrix2).resize(d);
}
for (int i = 0;i< matrixA(matrix1,matrix2).size();i++)
for (int j = 0;j < matrixA(matrix1, matrix2)[0].size();j++)
{
matrix5[i][j] = matrix1[i][j] + matrix2[i][j];
}
matrixA(matrix1, matrix2) = matrix5;
return matrixA(matrix1, matrix2);
};