Apr 20, 2015 at 8:46pm Apr 20, 2015 at 8:46pm UTC
hello
can someone fix my problems. i have no idea what is not working. i got this code with a vector<int>. i only changed this <int> to <vec> and nothing is working anymore.
i have to say i am a beginner
#include <algorithm>
#include <iostream>
#include <fstream>
#include <limits>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
//swap
void swap(vec& a, vec& b)
{
vec x = a;
a = b;
b = x;
}
//print the values
void printVector(std::vector<vec>& theVector)
{
for (unsigned int i = 0; i<theVector.size(); i++)
//std::cout << theVector[i] << ",";
std::cout << "\n";
}
//generate values
void generateAllPermutations(std::vector<vec>& toBePermuted, unsigned int nextIndex)
{
if (nextIndex == toBePermuted.size())
{
printVector(toBePermuted);
return;
}
for (unsigned int i = nextIndex; i<toBePermuted.size(); i++)
{
swap(toBePermuted[i], toBePermuted[nextIndex]);
generateAllPermutations(toBePermuted, nextIndex + 1);
swap(toBePermuted[i], toBePermuted[nextIndex]);
}
}
//generate values
void generateAllPermutations(std::vector<vec>& toBePermuted)
{
generateAllPermutations(toBePermuted, 0);
}
void setup()
{
std::vector<vec> theVector;
vec x(0, 1, 2);
vec y(3, 4, 5);
vec z(6, 7, 8);
theVector.push_back(x);
theVector.push_back(y);
theVector.push_back(z);
generateAllPermutations(theVector);
vec x;
std::cin >> x;
}
Apr 20, 2015 at 9:10pm Apr 20, 2015 at 9:10pm UTC
What is that vec
?
PS. Please use the code tags, when you post code.
Apr 21, 2015 at 6:42am Apr 21, 2015 at 6:42am UTC
sorry what you mean with code tags?
that vec is defined in the void setup () as vec x(1,1,1) vec y(1,1,1) and so on.....
that vec represents three different values of a range.
Apr 21, 2015 at 7:47am Apr 21, 2015 at 7:47am UTC
Add [co de] and [/code] around your code so it is formatted properly.
Where is the type vec
defined? It is not a standard type so it has to have been defined somewhere.
Apr 21, 2015 at 10:07am Apr 21, 2015 at 10:07am UTC
oh ok, sorry.....
the type vec is defined in another class:
[class DLL_API vec
{
public:
double x,y,z ;
vec();
vec(double _x, double _y , double _z );
bool operator == (vec other) ;
void operator += (vec other) ;
void operator -= (vec other) ;
vec operator + (vec other) ;
vec operator - (vec other) ;
void operator *= (double fac) ;
vec operator * (double fac) ;
vec operator / (double fac) ;
void operator /= (double fac) ;
vec operator /= (double &fac) ;
double operator *= (vec &other) ;
double operator * (vec &other) ;
double mag() ;
vec normalise() ;
double distanceTo( vec other ) ;
vec cross( vec &b ) ;
double angle(vec b) ;
double static angle_2D(double x1, double y1, double x2, double y2);
vec moveAlongDir( float d , vec a = vec(0,0,0));
void print() ;
};]
Apr 21, 2015 at 10:31am Apr 21, 2015 at 10:31am UTC
Why isn't that class definition included?
Apr 21, 2015 at 11:35am Apr 21, 2015 at 11:35am UTC
i have forgotten it, but that change anything
Apr 21, 2015 at 11:46am Apr 21, 2015 at 11:46am UTC
¿have you overload the insertion (>>) and extraction (<<) operators to make `vec' work with streams?
> and nothing is working anymore.
¿is it so hard to provide the error messages that your compiler is gently giving you?
Last edited on Apr 21, 2015 at 11:46am Apr 21, 2015 at 11:46am UTC