I have doubts with the following header: Material from OpenSceneGraph:
namespace osg {
/** Material - encapsulates OpenGL glMaterial state.*/
class OSG_EXPORT Material : public StateAttribute
{
public :
Material();
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Material(const Material& mat,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
in particular the const CopyOp& copyop=CopyOp::SHALLOW_COPY) part.
I am converting that constructor into this:
proc constructMaterial*(mat: Material, copyop: CopyOp = SHALLOW_COPY): Material {.constructor,importcpp: "osg::Material::Material(@)".}
The problem comes with SHALLOW_COPY which is an enum (Options) defined here. This is the default value for copyop whose type is CopyOp which is an object.
This creates a type mismatch error:
/home/jose/src/openscenegraph.nim/osg/Material.nim(30, 57) Error: type mismatch: got <Options> but expected 'CopyOp = object'
Any suggestion about how to handle this defaut value?
It seems like Options is implicitly convertible to CopyOp on C++ side, but this is not the case in nim. In general, C++ default arguments should be wrapped using arg: Type = initType(defaultValue) where toType is wrapper for implicit conversion constructor on the C++ side.
In C++ default arguments are constructor parameters and not actual values to be used (that's why it is posssible to use aggregate initalization in default parameters for example).
This is a much more convoluted example for wrapping different combinations of default parameters -
With generic argument
In C++ default arguments are
Thanks. Understood. It looks I have to do:
proc constructMaterial*(mat: Material, copyop: CopyOp = constructCopyOp(CopyFlags(SHALLOW_COPY))): Material {.constructor,importcpp: "osg::Material::Material(@)".} ## Copy constructor using CopyOp to manage deep vs shallow copy.