ILE C/C++ Programmer's Guide


Passing a _DecimalT Class Template Object to a Function

There are no default argument promotions on arguments that have _DecimalT class templates when the called function does not include a prototype. Any function definition containing _DecimalT class template arguments must be prototyped; otherwise, the compiler issues an error.

The following figure provides an example.

Figure 312. Example of Passing a _DecimalT Class Template Object to a Function



#include <bcd.h>
#include <iostream.h>

_DecimalT<3,1> d1 = __D("33.3");
_DecimalT<10,5> d2 = __D("55555.55555");
_DecimalT<28,0> d3 = __D("8888888888888888888888888888");

void func1( _DecimalT<3,1>, _DecimalT<10,5>,
_DecimalT<10,5>, _DecimalT<28,0>);

int main(void) 
{
func1(d1, d2, __D("999.99"), d3);
}
{
// func1 is prototyped
void func1(_DecimalT<3,1> x1, _DecimalT<10,5> x2,
_DecimalT<10,5> x3, _DecimalT<28,0> x4) {
// no runtime error when referencing x1, x2, x3 or x4
cout <<"x1 = " <<x1 <<endl;
cout <<"x2 = " <<x2 <<endl;
cout <<"x3 = " <<x3 <<endl;
cout <<"x4 = " <<x4 <<endl;
}

The output is:

+--------------------------------------------------------------------------------+
|x1 = 33.3                                                                       |
|x2 = 55555.55555                                                                |
|x3 = 999.99000                                                                  |
|x4 = 88888888888888888888888888888                                              |
+--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents ]