Matrix class problem

AGD

AGD

Soldato
Joined
23 Nov 2007
Posts
5,048
Hi, I'm trying to build a very simple matrix class using vectors (I know this is not ideal!).

Code:
#include<vector>

class matrix 
{
	vector <vector <double> > mat;
	unsigned rows,cols;
public:
	//constructor
	Matrix(unsigned rows_,unsigned cols_)
	{
		rows=rows_;
		cols=cols_;
		vector <double> vector1;
		for(int i=0;i<rows_;i++)
		{
			vector1.push_back(0.0);
			i++
		};
		mat.push_back(vector1);
		vector <double> vector2;
		for(int j=0;i<cols_;j++)
		{
			vector2.push_back(0.0);
			j++
		};
		mat.push_back(vector2);
	};
	//destructor
	~Matrix();
}

I just want to get to the stage where I can create a matrix of zeros as
Code:
matrix(3,2)
in a source file. At the moment I'm getting an error for the line:
Code:
vector <vector <double> > mat;
saying error C2143: syntax error : missing ';' before '<'

Please help!
 
Last edited:
Just realised that constructors must have the same name as the class so have changed that. Still have the same error though! It doesn't appear when I put the class in the main source file...maybe it hasn't linked #include<vector> correctly?
 
Back
Top Bottom