![]() |
Blitz Support : |
From: Julian Cummings (cummings_at_[hidden])
Date: 2004-06-16 18:07:56
Hi Andreas,
Andreas R. wrote:
>Does anybody know why casts work in assignments, but do not work in initialization statements?
>Example code:
> TinyVector<int, 2> matrix_size;
>
> Array<float, 2> matrix(matrix_size);
> // works:
> Array<int, 2> tmp(matrix_size);
> tmp = cast<int>(matrix);
>
> // doesn't work:
> Array<int, 2> tmp2 = cast<int>(matrix);
>->error: conversion from ` blitz::_bz_ArrayExpr<blitz::_bz_ArrayExprUnaryOp<blitz::FastArrayIterator<float, 2>, blitz::Cast<float, int> > >' to non-scalar type `blitz::Array<int, 2>' requested
>
>
>
The initialization statement fails because the Array constructor that
takes a _bz_ArrayExpr argument is labeled "explicit". This is needed to
avoid all sorts of types from potentially being converted into a
_bz_ArrayExpr and then used to construct an Array. If you really want
to construct an Array from an Array expression object, you can do so
explicitly.
Array<int, 2> tmp2(cast<int>(matrix));
Regards, Julian C.
-- Dr. Julian C. Cummings E-mail: cummings_at_[hidden] California Institute of Technology Phone: 626-395-2543 1200 E. California Blvd., Mail Code 158-79 Fax: 626-584-5917 Pasadena, CA 91125