M
martin.druon
Hi,
I created a template class to represent hypermatrix. I would like to
add methods where the number of parameters are checked during the
compilation time. For example :
template <size_t dim>
class Matrix
{
protected :
... // member datas
public:
...
Matrix( ????? ) { } // -> all of my parameters are "int"
...
void create ( ????? ) { } // -> all of my parameters are "int"
}
template <>
class Matrix<0>
{
protected :
... // member datas
public:
...
Matrix( ????? ) { }
...
void create ( ????? ) { }
}
in main.cpp :
int main(int argc, char **argv)
{
Matrix<3> m1(2, 5, 4); // OK
Matrix<3> m2(2, 5, 4, 8, 3); // compilation error
Matrix<3> m3; // OK
m3.create(4, 6, 5); // OK
m3.create(4); // compilation error
}
How I can do that ???
I try recursive method (with "operator ," overloading, ...) and with
lists but :
- either the number of parameters is not checked
- either the syntax is not like I want (without {...} or int[] = ...)
I try also to overload the "cast operator" but I never success... for
example to do this :
before : 1,2; // -> the ",2" is ignored (not "operator ," defined
with "int")
after : 1,2; // "1" is automaticaly cast to a new created class
(Lst for example) so the "," of ",2" is the "operator ," of this class
Lst
Do you understand ???
All of your ideas are welcome...
Thanks
I created a template class to represent hypermatrix. I would like to
add methods where the number of parameters are checked during the
compilation time. For example :
template <size_t dim>
class Matrix
{
protected :
... // member datas
public:
...
Matrix( ????? ) { } // -> all of my parameters are "int"
...
void create ( ????? ) { } // -> all of my parameters are "int"
}
template <>
class Matrix<0>
{
protected :
... // member datas
public:
...
Matrix( ????? ) { }
...
void create ( ????? ) { }
}
in main.cpp :
int main(int argc, char **argv)
{
Matrix<3> m1(2, 5, 4); // OK
Matrix<3> m2(2, 5, 4, 8, 3); // compilation error
Matrix<3> m3; // OK
m3.create(4, 6, 5); // OK
m3.create(4); // compilation error
}
How I can do that ???
I try recursive method (with "operator ," overloading, ...) and with
lists but :
- either the number of parameters is not checked
- either the syntax is not like I want (without {...} or int[] = ...)
I try also to overload the "cast operator" but I never success... for
example to do this :
before : 1,2; // -> the ",2" is ignored (not "operator ," defined
with "int")
after : 1,2; // "1" is automaticaly cast to a new created class
(Lst for example) so the "," of ",2" is the "operator ," of this class
Lst
Do you understand ???
All of your ideas are welcome...
Thanks