I'm trying to use the blitz++ matrix library in my code (Blitz++ Home Page) but am getting frustrated with how to use the blitz templates in my classes. All examples I have seen for this and any template simply use them in the main() function, which I cannot do for my program.
For example, to create a 3x3 array using blitz, their example is :
Code:
#include <blitz/array.h>
using namespace blitz;
int main()
{
Array<float,2> A(3,3), B(3,3), C(3,3);
A = 1, 0, 0,
2, 2, 2,
1, 0, 0;
B = 0, 0, 7,
0, 8, 0,
9, 9, 9;
C = A + B;
cout << "A = " << A << endl
<< "B = " << B << endl
<< "C = " << C << endl;
return 0;
}
Now this is fine so long as I'm restricting myself to the main routine, but I'm not and cannot do this. I want to achieve the following:
blitz.hpp
Code:
#include <cstdio>
#include <iostream>
#include <blitz/array.h>
class Test {
public:
Test();
~Test();
void showd();
private:
blitz::Array<double,2> d(3,3); // ** THIS IS NOT ALLOWED BUT I DON'T KNOW HOW TO CREATE A (3,3) ARRAY IN A CLASS
};
blitz.cpp
Code:
#include "blitz.hpp"
using namespace std;
using namespace blitz;
int main( int argc, const char* argv[] ){
Array<double,2> c(3,3);
c = 0;
c(0,0) = 1;
c(1,1) = 1;
c(2,2) = 1;
//cout << c << endl;
Test *t = new Test();
t->showd();
delete t;
exit(0);
}
Test::Test()
{
//c = new blitz::Array<double,2>(3,3);
//*c = 0;
blitz::Array<double,2> c(3,3);
blitz::Array<double,2> d(3,3); // this creates a LOCAL d, doesn't create a class instance of d to be 3,3
c = 0;
cout << c << endl;
}
Test::~Test()
{
}
void Test::showd()
{
d = 1;
cout << d << endl;
}
There MUST be a way of doing this otherwise there is no point in having Templates in C++ !
Your help is appreciated