I have written the following code using armadillo in c++. However, I cannot get any output (my outputs are cordX and cordY). Is there something wrong with my definition that it cannot give any output?
#include <iostream>
#include<armadillo>
using namespace std;
using namespace arma;
void myOrder(const mat &sOut, const mat &T, const mat &OL, mat &cordX, mat &cordY);
int main()
{
mat sOut;
sOut << 100 << 120 << endr;
mat T;
T << 20 << 20 << endr;
mat OL;
OL << 5 << 5 << endr;
mat locX;
mat locY;
myOrder(sOut, T, OL, locX, locY);
cout << locX << endl;
cout << locY << endl;
system("PAUSE");
return 0;
}
void myOrder(const mat &sOut, const mat &T, const mat &OL, mat &cordX, mat &cordY)
{
vector<double> U;
for (int i = 0; i < sOut(0) - T(0); i += T(0) - OL(0))
{
U.push_back(double(i));
}
vector<double> V;
for (int j = 0; j < sOut(1) - T(1); j += T(1) - OL(1))
{
V.push_back(double(j));
}
if ((double(U.back()) + 2*T(0) - OL(0) - 1) > sOut(0) && (double(U.back()) + T(0) !=sOut(0)))
{
U.push_back(sOut(0) - T(0) + 1);
}
colvec cordX = conv_to< colvec >::from(U);
if ((double(V.back()) + 2*T(1) - OL(1) - 1) > sOut(1) && (double(V.back()) + T(1) !=sOut(1)))
{
V.push_back(sOut(1) - T(1) + 1);
}
colvec cordY = conv_to< colvec >::from(V);
// return cordX, cordY;
}
You declare local variables with the same name as two of the arguments to the function,
cordX
andcordY
. Declaring them locally shadows the arguments, so the arguments will no longer be available to you. Building with more warning enabled should have led the compiler to give you warnings about this.I assume you meant to assign to the arguments, and not create two new variables.