I'm having trouble compiling the following header. It's my first experience with templates and I guess I'm getting something wrong. The compilers point errors at vector<vector<T>> data_;
and the operator overloading function. I would like the data_
vector to have the same type as the OptBaseMatrix
object but I'm not sure how to do it... 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 // OPTBASEMATRIX_H
UPDATE: Here is a snippet from the debugger 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've tried modifying vector> data_; by vector > data_; and still get the same error :/ I read somewhere that my template class header (.h) and implementation (.cpp) must be in the same file... is this possibly related ?
UPDATE 2: Wow ! I had forgotten "using namespace std;". The problem seems fixed now !