arrays-usertype.texi

来自「A C++ class library for scientific compu」· TEXI 代码 · 共 43 行

TEXI
43
字号
@node Array usertype@section Creating arrays of a user type@cindex Array of your own typesYou can use the @code{Array} class with types you have created yourself, ortypes from another library.  If you want to do arithmetic on the array,whatever operators you use on the arrays have to be defined on theunderlying type.For example, here's a simple class for doing fixed point computations in theinterval [0,1]:@smallexample@include examples/fixed-point.texi@end smallexampleThe function @code{huge(T)} returns the largest representable value for typeT; in the example above, it's equal to @code{UINT_MAX}.The @code{FixedPoint} class declares three useful operations: conversionfrom @code{double}, addition, and outputing to an @code{ostream}.  We canuse all of these operations on an @code{Array<FixedPoint>} object:@smallexample@include examples/fixed.texi@end smallexampleNote that the array @code{A} is initialized using a comma-delimited list of@code{double}; this makes use of the constructor @code{FixedPoint(double)}.The assignment @code{B = A + 0.05} uses@code{FixedPoint::operator+(FixedPoint)}, with an implicit conversion from@code{double} to @code{FixedPoint}.  Formatting the array @code{B} onto thestandard output stream is done using the output operator defined for@code{FixedPoint}.Here's the program output:@smallexample@include examples/fixed.out@end smallexample

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?