inheritance question

What I want to do is take a predefined matrix class (ideally from Boost.matrix) and use inheritance to make a pseudo custom matrix class.

What I have for starters is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

namespace blas=boost::numeric::ublas;

template <typename T>

class Matrix<T>: public blas::matrix<T> {
    public:
        void testing(){ std::cout << "Testing" << std::endl;};

};

using namespace std;
using namespace blas;

int main() {
    Matrix<int> test(3,3);

    for (int i; i < 3; i++){
        for (int j; j < 3; j++){
            test(i,j) = i*j;
        }
    }

    cout << test << endl;

}


The error that I am getting is:

1
2
3
4
5
inheritence.cc:10:7: error: ‘Matrix’ is not a template
inheritence.cc: In function ‘int main()’:
inheritence.cc:20:25: error: no matching function for call to ‘Matrix<int>::Matrix(int, int)’
inheritence.cc:10:41: note: candidates are: Matrix<int>::Matrix()
inheritence.cc:10:41: note:                 Matrix<int>::Matrix(const Matrix<int>&)


Now, I will admit that I am NOT an expert in template arguments or inheritance, so this is pretty cobbled together :)

Any suggestions/advice on how to resolve this problem will be welcomed.
i think you need not to inherit predefined class rather than doing so you can simply include that class and make your own class definition.
You need to define the ctor to call the base ctor. Note the changes to your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
 
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
 
namespace blas=boost::numeric::ublas;
 
template <typename T>
class Matrix: public blas::matrix<T> {
    public:
        Matrix(int x, int y){blas::matrix<T>(x,y);}
        void testing(){ std::cout << "Testing" << std::endl;};
 
};
 
using namespace std;
using namespace blas;
 
int main() {
    Matrix<int> test(3,3);
 
    for (int i; i < 3; i++){
        for (int j; j < 3; j++){
            test(i,j) = i*j;
        }
    }
 
    cout << test << endl;
 
}
Ah, thanks for the changes naraku! That did the trick and it compiled just fine and is working the way I wanted it to.
Topic archived. No new replies allowed.