Hello everybody!
I realized a Matrix class to practice and I have a problem I can not solve!
Here my problematic code:
Mtrx.h:
Code:
template <class T>
Mtrx::Mtrx(dim m, dim n, const bool random_constructed = false, const T min = static_cast<T>(0), const T max = static_cast<T> (10))
Mtrx.C
Code:
#include "Mtrx4.hxx"
#include <stdexcept>
#include <utility>
#include <iomanip>
#include <random>
#include <ctime>
std::allocator<double> Mtrx::alloc;
inline Mtrx::Mtrx():
NRows(0), NColumns(0), mtrx_begin(Mtrx::alloc.allocate(0)), mtrx_end(mtrx_begin), constructed(false) {}
template <class T>
Mtrx::Mtrx(dim m, dim n, const bool random_constructed, const T min, const T max):
NRows(m), NColumns(n), mtrx_begin(Mtrx::alloc.allocate(m*n)), mtrx_end(mtrx_begin+(m*n)), constructed(random_constructed)
{
if(random_constructed){
control(typeid(double) == typeid(min) && typeid(double) == typeid(max) ||
typeid(int) == typeid(min) && typeid(int) == typeid(max),
"ERRORE! Il costruttore pu� generare matrici random solo di tipo int o double");
if( typeid(int) == typeid(min) ){
std::default_random_engine e(std::time(0));
std::uniform_int_distribution<> u( min, max);
for(ppp i=mtrx_begin; i<mtrx_end; ++i) *i=u(e);
} else {
std::default_random_engine e(std::time(0));
std::uniform_real_distribution<> u( min, max);
for(ppp i=mtrx_begin; i<mtrx_end; ++i) *i=u(e);
}
}
}
And here the relative main section:
Code:
Mtrx rand1 ( 5, 5, bool); // ok
cout<<rand1<<endl;
Mtrx rand2 ( 7, 3, bool, -5, 20); // ok
cout<<rand2<<endl;
Mtrx rand3 ( 7, 7, bool, 0., 15.); // compilation error: undefined reference to
// "Mtrx::Mtrx<double>(unsigned long, unsigned, bool, double, double)"
// collect2: error: ld returned 1 exit status
I compiled in a Linux OS with g++ -std=c++11
Sorry for my bad english.