Note that there are some explanatory texts on larger screens.

plurals
  1. PO'Invalid use of void expression' passing arguments of functions
    text
    copied!<p>This is a piece of my code that solves systems of differential equations.</p> <pre><code>Vector dydx(Neq); void DiffEq(Vector x, Vector &amp;dydx) { dydx(0) = x(1); dydx(1) = -x(0); } double MidPoint(int n, Vector x) { double h=H/n; Matrix z(n+1,n+1); z.fillRow(0,x); DiffEq(x, dydx); z.fillRow(1,AddVec(x, dydx*h)); //Error: Invalid use of void expression for (int j=1; j&lt;n; j++) { DiffEq(z.getRow(j), dydx); z.fillRow(j+1, AddVec(z.getRow(j-1), dydx*h*2)); //error: void value not ignored as it ought to be } DiffEq(z.getRow(n), dydx); return 0.5*AddVec(z.getRow(n), z.getRow(n-1), dydx*h); //Error: Invalid use of void expression } </code></pre> <p>The classes Vector and Matrix are custom. This is Vector</p> <pre><code>class Vector { public: Vector(size_t size): vSize(size), vData(size){} int getSize(){return vSize;} double&amp; operator()(size_t i){return vData[i];} double operator()(size_t i) const {return vData[i];} void operator+(double d) // These only overload the Vector + int operator { for (int i=0; i&lt;vSize; i++) {vData[i]=vData[i]+d;} } void operator*(double d) { for (int i=0; i&lt;vSize; i++) {vData[i]=vData[i]*d;} } size_t vSize; vector&lt;double&gt; vData; }; </code></pre> <p>With a function</p> <pre><code>Vector AddVec(Vector v1, Vector v2) { Vector totVec(v1.getSize()); for (int i=0; i&lt;v1.getSize(); i++) {totVec(i) = v1(i) + v2(i);} return totVec; } </code></pre> <p>And the same function for 3 vectors.</p> <p>Now I realise that the error means that I'm passing void to some function, but I cannot figure out where things go wrong. When I try writing a test program, everything seems to work fine. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload