I am having trouble compiling the following header. This is my first experience with templates, and I assume that something is wrong with me. Compilers indicate errors in vector<vector<T>> data_;and the operator overload function. I would like the vector to data_have the same type as the object OptBaseMatrix, but I'm not sure how to do this ... I really don't know how to solve this problem. Help!
#ifndef OPTBASEMATRIX_H
#define OPTBASEMATRIX_H
#include <vector>
template<typename T>
class OptBaseMatrix
{
public:
vector<vector<T>> data_;
OptBaseMatrix(int rows, int cols);
~OptBaseMatrix();
void readMatrix();
void printMatrix();
int getRows();
int getCols();
OptBaseMatrix<T> operator+(const OptBaseMatrix<T>& matrix1, const OptBaseMatrix<T>& matrix2);
private:
int rows_;
int cols_;
};
#endif
The UPDATE . Here is a snippet from the debug log:
Error 1 error C2143: syntax error : missing ';' before '<' optbasematrix.h 17 TD2
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int optbasematrix.h 17 TD2
I tried changing the vector> data_; by vector> data_; and still get the same error: / I read somewhere that my template class header (.h) and implementation (.cpp) should be in the same file ... is this possibly related?
2: ! "using namespace std;". !