y***a 发帖数: 840 | 1 ok, I got this design problem and don't know whether I can do it with static
-typed languages such as C++.
I declared a template class:
template class my_template_1{ int array[x];}
this allows me to declare arbitrary array length my_template_1<5>, my_templa
te_1<500> etc.
the objects of classes instantiated by my_template_1 can have a operation mu
ltiplicaton:
my_template_1<2> * my_template_1<4> is my_template_1<8>,
my_template_1<20> * my_template_1<3> is my_template_1<60>, and so on.
I |
y***a 发帖数: 840 | 2 is this related with something called generative template?
I wish I attended the programming language courses when I was in school.
static
templa
mu
【在 y***a 的大作中提到】 : ok, I got this design problem and don't know whether I can do it with static : -typed languages such as C++. : I declared a template class: : template class my_template_1{ int array[x];} : this allows me to declare arbitrary array length my_template_1<5>, my_templa : te_1<500> etc. : the objects of classes instantiated by my_template_1 can have a operation mu : ltiplicaton: : my_template_1<2> * my_template_1<4> is my_template_1<8>, : my_template_1<20> * my_template_1<3> is my_template_1<60>, and so on.
|
t****t 发帖数: 6806 | 3 you have A and A and you want A. so define a function that tak
es A and A and return A. i think it can not be any more straightf
orward.
static
templa
mu
【在 y***a 的大作中提到】 : ok, I got this design problem and don't know whether I can do it with static : -typed languages such as C++. : I declared a template class: : template class my_template_1{ int array[x];} : this allows me to declare arbitrary array length my_template_1<5>, my_templa : te_1<500> etc. : the objects of classes instantiated by my_template_1 can have a operation mu : ltiplicaton: : my_template_1<2> * my_template_1<4> is my_template_1<8>, : my_template_1<20> * my_template_1<3> is my_template_1<60>, and so on.
|
y***a 发帖数: 840 | 4 thanks for the reply. but I don't quite understand how to do that.
I think the compiler only know what x*y is when it sees the user's code as T
2*T3.
Can you be more specific? thanks
straightf
【在 t****t 的大作中提到】 : you have A and A and you want A. so define a function that tak : es A and A and return A. i think it can not be any more straightf : orward. : : static : templa : mu
|
t****t 发帖数: 6806 | 5 template
A foo(const A&, const A&);
isn't it straightforward?
T
【在 y***a 的大作中提到】 : thanks for the reply. but I don't quite understand how to do that. : I think the compiler only know what x*y is when it sees the user's code as T : 2*T3. : Can you be more specific? thanks : : straightf
|