2

I am quite suprised that it's not possible to multiply two valarrays if one is of type double and second is int.

Why is that?

std::valarray<int> vali(3);
vali[0] = 0;
vali[1] = 1;
vali[2] = 2;

std::valarray<double> vald(3);
vald[0] = 0;
vald[1] = 1;
vald[2] = 2;

std::valarray<double> result(3);

result = vald * vali;

compiler error:

error C2678: binary '*' : no operator found which takes a left-hand operand of type 'std::valarray<double>'

It's same for both g++ and msvc++ compiler.

Tomas
  • 2,170
  • 10
  • 14
  • The standard currently does not define such operator, that's all. What kind of answer do you expect? – Holt Apr 12 '16 at 19:26
  • In my opinion it would be an useful feature. I believe there is a reason why c++ standard doesn't define it. I am just curious. – Tomas Apr 12 '16 at 19:36

0 Answers0