由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - recursive template?
相关主题
C++ Template Questionclass D:public B;
一道面试怪题C++. (转载)C++ memcpy declaration use restrict keyword?
请问如何把初始化一个const 的vector (or array) in a class?tempalte as the overloaded conversion operator
C++怎样设置全局变量[合集] 为什么不能: declare a static memeber func
C++ template questionWhat happens when recursion functions are declared inline?
[合集] 又被羞辱了一把... (转载)这个程序为什么不能运行?
基础问题:在header里面define function有关 template function 的一个问题
a c++ question for template[合集] 请教: 模板类之继承的一个小问题
相关话题的讨论汇总
话题: template话题: my话题: templa话题: recursive话题: int
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
[合集] 请教: 模板类之继承的一个小问题C++ template question
template 疑问[合集] 又被羞辱了一把... (转载)
What're the three types of memory allocated for C++ variables?基础问题:在header里面define function
C++ class cross reference problema c++ question for template
C++ Template Questionclass D:public B;
一道面试怪题C++. (转载)C++ memcpy declaration use restrict keyword?
请问如何把初始化一个const 的vector (or array) in a class?tempalte as the overloaded conversion operator
C++怎样设置全局变量[合集] 为什么不能: declare a static memeber func
相关话题的讨论汇总
话题: template话题: my话题: templa话题: recursive话题: int