FILENAME: example4.cpp
Program:
/*
* Example program illustrating type * conversion. Template functions will not do * automatic conversion, but Math.h++ provides * explicit casting between collection classes * of different datatypes. */ // Include the RWMathVec class header files. #include <rw/math/mathvec.h> #include <iostream.h> // Initial data for the vectors. double adata[] = {1., 3., -2., -6., 7.}; int idata[] = {2, 6, -4, 2, 1}; main() { // Construct the vectors V and iV from the // arrays defined above. RWMathVec<double> V(adata, 5); RWMathVec<int> iV(idata, 5); /* * Output the dot product of the two vectors. * Note that the function dot has prototype * template<class T> dot(RWMathVec<T>&, RWMathVec<T>&), * so to use dot, the RWMathVec<int> is cast to * RWMathVec<double> to get a match. */ RWMathVec<double> temp = RWConvertMathVec<int,double>(iV); cout << dot (V, RWConvertMathVec<int,double>(iV)); }
Sample Input:
None required.
Sample Output:
23>
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.