[Insight-users] error
Zachary Pincus
zpincus at stanford.edu
Wed May 18 20:38:49 EDT 2005
[Oops, forgot to CC the insight list on this one. Well, for the record,
here is an explanation of why you need const variables, or similar, for
template parameters.]
Hello,
Recall that templates are a compile-time feature. So the compiler needs
to have access to the exact values of the template parameters.
Specifically integer template parameters must be something called an
"integral constant expression," which is a way of saying that it is an
expression that the compiler has access to the value of at
compile-time, and can guarantee that the value will not change during
run-time.
Here is a list of expression types that are "integral constants" :
http://www-eleves-isia.cma.fr/documentation/BoostDoc/boost_1_29_0/more/
int_const_guidelines.htm
The easiest way to make a value an integral constant is either to
declare it globally as:
const int size = 5;
or if you are within a class:
class foo {
static const int size = 5;
};
then
template <int s> class bar {};
bar< size > x;
bar< foo::size> x;
will compile fine.
Simple numeric operators work too:
bar< -size >x;
bar< size + foo::size > x;
will also compile.
Zach Pincus
Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine
On May 17, 2005, at 9:35 AM, Tina Wang wrote:
> hi,
>
> I am defining a vector type as:
>
> typedef itk::Vector< float, 3 > MeasurementVectorType;
>
> Now I want to change 3 with different value by
> repalcing it with a variable such as
> int size = 4;
> typedef itk::Vector< float, size
>> MeasurementVectorType;
>
> but I always get an error message "error C2973:
> 'Vector' : invalid template argument
> 'NVectorDimension'",
> Could anyone tell me how to define or change the
> MeasurementVectorType with diefferent size.
>
> Thanks,
>
> tina
>
>
>
> Yahoo! Mail
> Stay connected, organized, and protected. Take the tour:
> http://tour.mail.yahoo.com/mailtour.html
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list