Recently, I have been working in JS canvas to make fractals in two and three dimensions. Right now, I am working on porting my project into C++ via SDL and Eigen. It's pretty important that I am able to compose functions for later use. The code below is my first attempt at making a composite function factory:
std::function< Eigen::Vector3f(Eigen::Vector3f) > compose3d(std::function<
Eigen::Vector3f(Eigen::Vector3f) > a, std::function<
Eigen::Vector3f(Eigen::Vector3f) > b){
return [&](Eigen::Vector3f vec)->Eigen::Vector3f{
return b(a(vec));
};
}
Currently this is giving me a duplicate symbol error during linking. If this code is removed, the error goes away. I have made sure that this function is inside of a ifndef
section of my header. I know it is not best practice to have functions fully defined in the header, but would like to get things working before refactoring.
Overall, I just want to know if this problem is an error in the writing of the function if I should look somewhere else in my code for duplicate definitions. I am aware that it is considered better to create lists of function pointers rather than to create lists of functions and I will work on implementing that after this linker error is solved.
Sorry if this is horrendous, I haven't been writing C++ very long and this is my first lambda attempt.
Thanks!