hungpham2511 / toppra

robotic motion planning library
https://hungpham2511.github.io/toppra/index.html
MIT License
603 stars 167 forks source link

Cannot convert from 'initializer list' to 'toppra::BoundaryCond' #245

Open maxpla3 opened 7 months ago

maxpla3 commented 7 months ago

While compiling the project in VS Studio 2022 I get following error: error C2440: 'initializing': cannot convert from 'initializer list' to 'toppra::BoundaryCond'

5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(79,18): error C2440: 'initializing': cannot convert from 'initializer list' to 'toppra::BoundaryCond'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(79,18): message : 'toppra::BoundaryCond::BoundaryCond': ambiguous call to overloaded function
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\src\toppra/geometric_path/piecewise_poly_path.hpp(23,3): message : could be 'toppra::BoundaryCond::BoundaryCond(int,const toppra::Vector)'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\src\toppra/geometric_path/piecewise_poly_path.hpp(21,3): message : or       'toppra::BoundaryCond::BoundaryCond(int,const std::vector<toppra::value_type,std::allocator<toppra::value_type>> &)'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(79,18): message : while trying to match the argument list '(int, initializer list)'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(95,18): error C2440: 'initializing': cannot convert from 'initializer list' to 'toppra::BoundaryCond'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(95,18): message : 'toppra::BoundaryCond::BoundaryCond': ambiguous call to overloaded function
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\src\toppra/geometric_path/piecewise_poly_path.hpp(23,3): message : could be 'toppra::BoundaryCond::BoundaryCond(int,const toppra::Vector)'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\src\toppra/geometric_path/piecewise_poly_path.hpp(21,3): message : or       'toppra::BoundaryCond::BoundaryCond(int,const std::vector<toppra::value_type,std::allocator<toppra::value_type>> &)'
5>C:\Users\Default\git\ToppRaMinimal\toppra\toppra\cpp\tests\test_cubic_spline.cpp(95,18): message : while trying to match the argument list '(int, initializer list)'
...

In piecewise_poly_path.hpp we have:

  BoundaryCond(int order, const std::vector<value_type> &values);  
  BoundaryCond(int order, const Vector values);

The compiler does not know which constructor to use when calling e.g. BoundaryCond bc{1, {0, 0, 0, 0, 0, 0}};. I think this is because std::vector and toppra::Vector both support initializer lists so the compiler cannot decide which type it has to use.

Solution: Explicitly declare std::vector<value_type> before the initializer list in the constructor call like this: BoundaryCond{3, std::vector<value_type>{1.52, 7.21, 9.31, 2.52, 4.41, 5.54}}