I want to use (for example) a System.Drawing.PointF variable in C++ (/clr), using msclr::interop::marshal_as(). To do so, I add a template specialization as follows:
using namespace System::Drawing;
namespace msclr {
namespace interop {
template<>
inline mynmsp::Punt marshal_as<mynmsp::Punt, PointF>(PointF const &from) {
PointF cpf(from);
return mynmsp::Punt(cpf.X, cpf.Y);
}
}
}
I was hoping to achieve this without the additional instance 'PointF cpf(from);' However, the const reference makes this impossible as far as I can see, and the PointF &from invocation won't be accepted without the const. Explicitly adding X() or X.get() does not help. I should add about myself that my C# is horrible, trying to get by with the minimum, do the real work in C++. Thanks in advance, Jan
PS: The comment by Hans Passant explains that the workaround comes at no cost in at least the Release build. I consider that a solution, because now I can add this as a comment and I will certainly keep basic jitter optimizations. Thanks.