Using Class Template in Visual C++


I wrote template which return matrix in Window Form Application .My template is below:

class matrix1 {

T *data;

const unsigned rows, cols, size;
matrix1(unsigned r, unsigned c) : rows(r), cols(c), size(r*c) {

data = new T[size];
~matrix1() { delete data; }
void setValue(unsigned row, unsigned col, T value) {
data[(row*cols)+col] = value;
T getValue(unsigned row, unsigned col) const {
return data[(row*cols)+col];

I wrote this code in Main Project File in Windows Form Application.I defined 341*680 matrix with using this template :


I used function that do operation on this template and I defined it like this:

[code]void function(matrix1 &b,array< double>^ temp)[/code]

And call it:

(temp is one dimensinonal data array that I have to use for my programming algorithm)

For Example;When I want to print data that is located in the first row and first column.

Visual C++ recognise getvalue and setvalue function ,but couldn't print anything and gave a lot of error interested with matrix1 template

I tried this template and function on CLR Console Application and it worked.How could I do this On Windows Form Application.And Where should I locate template class on Windows Form Application.

Best Regards...

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!