Hi , the program errors is coming in Visual Studio 2015 in Windows 10 . I tried linux where it says "Segmentation fault" . The list of errors is mentioned first . Then the Header.h , Then Header.cpp and finally Source.cpp .
[ERRORS]
Severity Code Description Project File Line Suppression State
Error LNK2005 "class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > __cdecl definematrix(int,int)" (?definematrix@@YA?AV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@HH@Z) already defined in Header.obj Project10 C:\Users\chica\Documents\Visual Studio 2015\Projects\Project10\Project10\Source.obj 1
Error LNK2005 "class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > __cdecl defmatrix(class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > >,class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > >)" (?defmatrix@@YA?AV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@V12@0@Z) already defined in Header.obj Project10 C:\Users\chica\Documents\Visual Studio 2015\Projects\Project10\Project10\Source.obj 1
Error LNK2005 "public: class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > __thiscall matrix::matrixA(class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > &,class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > &)" (?matrixA@matrix@@QAE?AV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@AAV23@0@Z) already defined in Header.obj Project10 C:\Users\chica\Documents\Visual Studio 2015\Projects\Project10\Project10\Source.obj 1
Error LNK2019 unresolved external symbol "public: class std::vector<class std::vector<int,class std::allocator<int> >,class std::allocator<class std::vector<int,class std::allocator<int> > > > __thiscall matrix::definematrix(int,int)" (?definematrix@matrix@@QAE?AV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@HH@Z) referenced in function _main Project10 C:\Users\chica\Documents\Visual Studio 2015\Projects\Project10\Project10\Source.obj 1
Error LNK1120 1 unresolved externals Project10 C:\Users\chica\Documents\Visual Studio 2015\Projects\Project10\Debug\Project10.exe 1
[Header. H]
#pragma once
#include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
class matrix {
public:
int definematrixrow;
int definematrixcolumn;
vector<vector<int>> matrix_shishir(int definematrixrow, int definematrixcolumn);
vector<vector<int>> matrix_shi(int definematrixrow, int definematrixcolumn);
vector<vector<int>> matrix_x(vector<vector<int>> matrix3);
vector<vector<int>> matrix_y(vector<vector<int>> &matrix4);
vector<vector<int>> definematrix(int definematrixrow, int definematrixcolumn)
{
int matrixcolumn = definematrixcolumn;
int matrixrow = definematrixrow;
vector<std::vector<int>> matrix_shi(definematrixrow, std::vector<int>(definematrixcolumn));
matrix_shi.resize(definematrixrow);
for (int i = 0;i < definematrixcolumn;i++)
matrix_shi[i].resize(definematrixcolumn);
return matrix_shi;
}
//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);
};
matrix my_matrix;
int m, n;
cout << "enter the matrix row number";
cin >> m;
my_matrix.setRow(m);
vector<vector<int>> matrix_shi;
vector<vector<int>> matrix_shishir;
Put simply, do not #include cpp files. Certainly do not stick #pragma once in a cpp file ; that just suggests you don't understand what a cpp file is for and you're just writing code at random hoping to make things work.
@Repeater . Thanks for your reply . I am a beginner . Would it be ok if i asked what #pragma once does ? can you please clarify about what you stated about cpp file . I would be most grateful