-3

Can u help me please. I get this error: expected unqualified-id before 'template', in c++.

Matrix.h:

#ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <iostream>

using namespace std;

template <typename T>
class Matrix {
    int     m;
    int     n;
    T   **data;

public:
    void    newData(int, int);
}

#endif

Matrix.cpp:

#include "Matrix.h"


template <typename T>    // here is the error
void    Matrix<T>::newData(int m, int n) {
    int     i;
    int     j;

    this->m = 0;
    this->n = 0;
    this->data = NULL;
    if (m <= 0 || n <= 0)
        return;
    this->data = new T*[m];
    for (i = 0; i < m; i++)
    {
        this->data[i] = new T[n];
        for (j = 0; j < n; j++)
            this->data[i][j] = 0;
    }
    this->m = m;
    this->n = n;
}

What does the compiler want to tell me?

How can I fix these errors?

1 Answers1

1

You forgot ; in the end of class.

template <typename T>
class Matrix {
    int     m;
    int     n;
    T   **data;

public:
    void    newData(int, int);
}; // <------------------------- Here
Alex
  • 9,891
  • 11
  • 53
  • 87