r***e 发帖数: 2000 | 1 I was reading the system library of complex number
and have some questions:
1) Should it be a class or a struc?
the system makes it a struc;
2) Although it is a struct, the system library provides
accessor functions such as real(), etc. why?
3) Why it is implemented as a template?
I would assume make it two doubles and type conversion
can take care of int and float, etc.
Thanks. |
N***m 发帖数: 4460 | 2
Struct works well in legacy code, and it may cause less trouble in
transfering data.
Isn't it natural to have such a function?
Template was designed to solve such problems. But you still think
in the same old way.
【在 r***e 的大作中提到】 : I was reading the system library of complex number : and have some questions: : 1) Should it be a class or a struc? : the system makes it a struc; : 2) Although it is a struct, the system library provides : accessor functions such as real(), etc. why? : 3) Why it is implemented as a template? : I would assume make it two doubles and type conversion : can take care of int and float, etc. : Thanks.
|
t****t 发帖数: 6806 | 3 1 class or struct doesn't matter. only difference is default accessibility.
what matters is, complex<> are "literal types". i assume this is for
compatibility and implementation convenience.
2 the default accessibility is for backward compatibility.
3 for floating point calculation, precision matters. why system provides
float, instead of letting everyone use double?
【在 r***e 的大作中提到】 : I was reading the system library of complex number : and have some questions: : 1) Should it be a class or a struc? : the system makes it a struc; : 2) Although it is a struct, the system library provides : accessor functions such as real(), etc. why? : 3) Why it is implemented as a template? : I would assume make it two doubles and type conversion : can take care of int and float, etc. : Thanks.
|
r***e 发帖数: 2000 | 4
.
What is a 'literal type'? What is the common practice for
a 'literal type', a class or a struct?
I see.
I see, thank you.
【在 t****t 的大作中提到】 : 1 class or struct doesn't matter. only difference is default accessibility. : what matters is, complex<> are "literal types". i assume this is for : compatibility and implementation convenience. : 2 the default accessibility is for backward compatibility. : 3 for floating point calculation, precision matters. why system provides : float, instead of letting everyone use double?
|
t****t 发帖数: 6806 | 5 google is your friend.
【在 r***e 的大作中提到】 : : . : What is a 'literal type'? What is the common practice for : a 'literal type', a class or a struct? : I see. : I see, thank you.
|
N***m 发帖数: 4460 | 6 大侠你很空啊,呵呵。
【在 t****t 的大作中提到】 : google is your friend.
|
r*******m 发帖数: 109 | 7 once you start get used to template, its really the wonderful thing in C++.
【在 r***e 的大作中提到】 : I was reading the system library of complex number : and have some questions: : 1) Should it be a class or a struc? : the system makes it a struc; : 2) Although it is a struct, the system library provides : accessor functions such as real(), etc. why? : 3) Why it is implemented as a template? : I would assume make it two doubles and type conversion : can take care of int and float, etc. : Thanks.
|
h*******s 发帖数: 8454 | 8 google得结果似乎都是在说c++0x里面规定了可以有user defined literal,没找到哪
里说complex是literal type啊
大牛有空多解释一下?
【在 t****t 的大作中提到】 : google is your friend.
|
|
t****t 发帖数: 6806 | 9 literal type is not user defined literal.
【在 h*******s 的大作中提到】 : google得结果似乎都是在说c++0x里面规定了可以有user defined literal,没找到哪 : 里说complex是literal type啊 : 大牛有空多解释一下?
|