I am attempting to pass a std::vector of a custom class datatype to an function external to the main class. However, I am not sure of the best way to do this. Currently it produces segmentation faults.
Let me explain, I have tried to create a minimum reproducible example below:
I have a class in a header file Poses.h
class Pose
{
public:
double x;
Pose(double x_)
{
x = x_;
}
};
In the main header, lets call it foo.h
#include <vector>
#include "foofcn.h"
class foo{
public:
void begin()
{
std::vector<Pose> myPoses;
myPoses[0] = Pose(1);
myPoses[1] = Pose(2);
foofcn(myPoses);
}
};
Where foofcn.h
is
#include <vector>
#include "Pose.h"
#include <iostream>
void foofcn(std::vector<Pose> myFooPoses)
{
int xx;
xx = myFooPoses[0].x;
std::cout << xx << std::endl;
}
This currently produces an error: Segmentation fault (core dumped)
Any help is appreciated