ILE C/C++ Programmer's Guide


Passing a Pointer to a _DecimalT Class Template Object

When you pass a pointer to a _DecimalT class template object, the _DecimalT template-class argument in the function call must be the same class template as the _DecimalT class template in the function prototype.

If overflow occurs in a function call with _DecimalT class template arguments, a run-time exception is generated.

The following figure provides an example of passing a pointer to a _DecimalT class template object.

Figure 313. Example of Passing a Pointer to a _DecimalT Class Template Object



// This program shows how to pass a pointer to a _DecimalT template
// class object to a function.

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

_DecimalT<5,2> var=__D("123.45");
_DecimalT<5,2> *p=&var;

_DecimalT<5,2> *func_1(_DecimalT<5,2> *);

int main(void)
{

// Call function with pointer to _DecimalT class template argument.
// The value that it returns is a pointer to a _DecimalT
// class template object.

_DecimalT<5,2> *tempvar;
tempvar = func_1(p);

if(tempvar == 0)
{
cout <<"Function call not successful" <<endl <<endl;
}
else
{
cout <<"The bcd value is " << *tempvar <<endl <<endl;
}
}
_DecimalT<5,2> *func_1(_DecimalT<5,2> *q)
{
return q;
}

The output is:

+--------------------------------------------------------------------------------+
|The bcd value is 123.45                                                         |
+--------------------------------------------------------------------------------+


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