U
user790
Hello,
I am compiling the following code
<code>
template < unsigned int I >
class A {};
template < int I >
class B {};
template < int I >
B<-I> foo(A<I> const &)
{
return B<-I>();
}
template < int I >
void bar(A<I> const &)
{
}
int main()
{
A<1> a;
foo(a); // warning here
bar(a);
return 0;
}
</code>
At the indicated line, Visual Studio 2009 emits the following warning:
warning C4146: unary minus operator applied to unsigned type, result
still unsigned
I don't really understand the warning. It seems to me that the problem
could be the unsigned int to int conversion of the template argument
-- once it has been converted to int, appling the unary minus operator
should be a problem. But I get this warning for foo and no warning for
bar. What is the reason behind this?
More importantly, I would like to know if there would be any work-
around to avoid the warning.
Thank you,
Paul
I am compiling the following code
<code>
template < unsigned int I >
class A {};
template < int I >
class B {};
template < int I >
B<-I> foo(A<I> const &)
{
return B<-I>();
}
template < int I >
void bar(A<I> const &)
{
}
int main()
{
A<1> a;
foo(a); // warning here
bar(a);
return 0;
}
</code>
At the indicated line, Visual Studio 2009 emits the following warning:
warning C4146: unary minus operator applied to unsigned type, result
still unsigned
I don't really understand the warning. It seems to me that the problem
could be the unsigned int to int conversion of the template argument
-- once it has been converted to int, appling the unary minus operator
should be a problem. But I get this warning for foo and no warning for
bar. What is the reason behind this?
More importantly, I would like to know if there would be any work-
around to avoid the warning.
Thank you,
Paul