error: expected initializer before ‘addRow’

I got this error message when I tried to compile my matrix.cpp file:


matrix.cpp:28: error: expected initializer before ‘addRow’


Here is matrix.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 *  matrix.cpp
 *  
 *
 *  Created by Matthew Dunson on 12/7/09.
 *  Copyright 2009 The Ohio State University. All rights reserved.
 *
 */

#include "matrix.h"

matrix::matrix (int length)
{
	this->length = length ? length: default_length;
	for (int i = 0; i < length; i++)
	{
		vector<int> elements;
		for (int j = 0; j < length; j++)
		{
			elements.push_back (0);
		}
		rows.push_back (elements);
	}
}

int matrix::default_length (1);

void matrix::matrix addRow (int row, vector<int> columns)
{
	for (int i = 0; i < (int) columns.size (); i++)
	{
		this->rows[row][i] = columns[i];
	}
}
	

matrix operator<<(ostream &out, const matrix &one)
{
	for (int i = 0; i < one.length; i++)
	{
		for (int j = 0; j < one.length; j++)
		{
			out << one.rows[i][j];
		}
		out << endl;
	}
}


Why did I get this error message and how can I fix it?
Last edited on
void matrix::matrix addRow (int row, vector<int> columns)

I suppose here must be
void matrix::addRow (int row, vector<int> columns)
Topic archived. No new replies allowed.