Dev - C++ - Como heredar de una clase

 
Vista:

Como heredar de una clase

Publicado por MyMail (2 intervenciones) el 21/10/2013 18:56:38
Hi there
I have a Base Class with pure virtual function and 3 private variables like this

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
class IMatriz {
	int **m;
	int numRows;
	int numColumns;
	public:
		IMatriz()
		{
			numRows = 0;
			numColumns = 0;
			m = NULL;
		}
		IMatriz(int r, int c)
		{
			numRows = r;
			numColumns = c;
			m = new int* [numRows];
			for(int i=0; i<numRows; i++)
				m[i] = new int [numColumns];
		}
 
	virtual void setSize(int r, int c) = 0;
	virtual void setValue(int row, int col, int val) = 0;
	virtual int getValue(int row, int col) = 0;
	virtual int getNumRows() = 0;
	virtual int getNumColumns() = 0;
	virtual void mult(IMatriz a, IMatriz b) = 0;
	virtual void print(void) = 0;
};

**I need to implement the derived class call Matriz
But I dont have the minimal idea how to do that

The main program has to be like this**


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
main()
{
	Matriz m;
	Matriz a(3,2);
	Matriz b(2,3);
	a.setValue(0,0,7);
	a.setValue(1,0,1);
	a.setValue(2,0,8);
	a.setValue(0,1,2);
	a.setValue(1,1,5);
	a.setValue(2,1,6);
	b.setValue(0,0,2);
	b.setValue(1,0,3);
	b.setValue(0,1,5);
	b.setValue(1,1,4);
	b.setValue(0,2,8);
	b.setValue(1,2,9);
	m.mult(a,b);
	m.print();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder