Thread: Using Class Template in Visual C++

  1. #1
    Registered User
    Join Date
    May 2009

    Using Class Template in Visual C++


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

    template<class T>
        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:

    void function(matrix1<double> &b,array< double>^ temp)
    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...
    Last edited by yalcin; 06-30-2009 at 06:36 AM.

  2. #2
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    The Great White North
    gave a lot of error interested with array1 template
    Show us the array or array1 template

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Also, match array forms of new and delete.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM