Mark all single-argument constructors in user_objects.h as explicit.

This avoids accidental implicit conversions.

Also included some constructors with multiple arguments, where default values mean that the single-argument constructor is valid.

PiperOrigin-RevId: 772117936
Change-Id: I57e54a373593080e9d68961b00488c7a70f1aff8
This commit is contained in:
Nimrod Gileadi
2025-06-16 11:59:42 -07:00
committed by Copybara-Service
parent 1f0e4891c2
commit e2e2932fe6
+25 -25
View File
@@ -388,8 +388,8 @@ class mjCBody : public mjCBody_, private mjsBody {
friend class mjXURDF;
public:
mjCBody(mjCModel*); // constructor
~mjCBody(); // destructor
explicit mjCBody(mjCModel*);
~mjCBody();
// API for adding objects to body
mjCBody* AddBody(mjCDef* = 0);
@@ -571,7 +571,7 @@ class mjCJoint : public mjCJoint_, private mjsJoint {
friend class mjXURDF;
public:
mjCJoint(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCJoint(mjCModel* = nullptr, mjCDef* = nullptr);
mjCJoint(const mjCJoint& other);
mjCJoint& operator=(const mjCJoint& other);
@@ -651,7 +651,7 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
friend class mjXURDF;
public:
mjCGeom(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCGeom(mjCModel* = nullptr, mjCDef* = nullptr);
mjCGeom(const mjCGeom& other);
mjCGeom& operator=(const mjCGeom& other);
@@ -716,7 +716,7 @@ class mjCSite : public mjCSite_, private mjsSite {
friend class mjXURDF;
public:
mjCSite(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCSite(mjCModel* = nullptr, mjCDef* = nullptr);
mjCSite(const mjCSite& other);
mjCSite& operator=(const mjCSite& other);
@@ -766,7 +766,7 @@ class mjCCamera : public mjCCamera_, private mjsCamera {
friend class mjXWriter;
public:
mjCCamera(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCCamera(mjCModel* = nullptr, mjCDef* = nullptr);
mjCCamera(const mjCCamera& other);
mjCCamera& operator=(const mjCCamera& other);
@@ -812,7 +812,7 @@ class mjCLight : public mjCLight_, private mjsLight {
friend class mjXWriter;
public:
mjCLight(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCLight(mjCModel* = nullptr, mjCDef* = nullptr);
mjCLight(const mjCLight& other);
mjCLight& operator=(const mjCLight& other);
@@ -897,7 +897,7 @@ class mjCFlex: public mjCFlex_, private mjsFlex {
friend class mjXWriter;
public:
mjCFlex(mjCModel* = nullptr);
explicit mjCFlex(mjCModel* = nullptr);
mjCFlex(const mjCFlex& other);
mjCFlex& operator=(const mjCFlex& other);
@@ -997,7 +997,7 @@ class mjCMesh: public mjCMesh_, private mjsMesh {
friend class mjCModel;
public:
mjCMesh(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCMesh(mjCModel* = nullptr, mjCDef* = nullptr);
mjCMesh(const mjCMesh& other);
mjCMesh& operator=(const mjCMesh& other);
~mjCMesh();
@@ -1200,7 +1200,7 @@ class mjCSkin: public mjCSkin_, private mjsSkin {
friend class mjXWriter;
public:
mjCSkin(mjCModel* = nullptr);
explicit mjCSkin(mjCModel* = nullptr);
mjCSkin(const mjCSkin& other);
mjCSkin& operator=(const mjCSkin& other);
~mjCSkin();
@@ -1258,7 +1258,7 @@ class mjCHField : public mjCHField_, private mjsHField {
friend class mjXWriter;
public:
mjCHField(mjCModel* model);
explicit mjCHField(mjCModel* model);
mjCHField(const mjCHField& other);
mjCHField& operator=(const mjCHField& other);
~mjCHField();
@@ -1310,7 +1310,7 @@ class mjCTexture : public mjCTexture_, private mjsTexture {
friend class mjXWriter;
public:
mjCTexture(mjCModel*);
explicit mjCTexture(mjCModel*);
mjCTexture(const mjCTexture& other);
mjCTexture& operator=(const mjCTexture& other);
~mjCTexture();
@@ -1371,7 +1371,7 @@ class mjCMaterial : public mjCMaterial_, private mjsMaterial {
friend class mjXWriter;
public:
mjCMaterial(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCMaterial(mjCModel* = nullptr, mjCDef* = nullptr);
mjCMaterial(const mjCMaterial& other);
mjCMaterial& operator=(const mjCMaterial& other);
@@ -1411,7 +1411,7 @@ class mjCPair : public mjCPair_, private mjsPair {
friend class mjXWriter;
public:
mjCPair(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCPair(mjCModel* = nullptr, mjCDef* = nullptr);
mjCPair(const mjCPair& other);
mjCPair& operator=(const mjCPair& other);
@@ -1460,7 +1460,7 @@ class mjCBodyPair : public mjCBodyPair_, private mjsExclude {
friend class mjCModel;
public:
mjCBodyPair(mjCModel*);
explicit mjCBodyPair(mjCModel*);
mjCBodyPair(const mjCBodyPair& other);
mjCBodyPair& operator=(const mjCBodyPair& other);
@@ -1506,7 +1506,7 @@ class mjCEquality : public mjCEquality_, private mjsEquality {
friend class mjXWriter;
public:
mjCEquality(mjCModel* = 0, mjCDef* = 0);
explicit mjCEquality(mjCModel* = 0, mjCDef* = 0);
mjCEquality(const mjCEquality& other);
mjCEquality& operator=(const mjCEquality& other);
@@ -1545,7 +1545,7 @@ class mjCTendon : public mjCTendon_, private mjsTendon {
friend class mjXWriter;
public:
mjCTendon(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCTendon(mjCModel* = nullptr, mjCDef* = nullptr);
mjCTendon(const mjCTendon& other);
mjCTendon& operator=(const mjCTendon& other);
~mjCTendon();
@@ -1641,7 +1641,7 @@ class mjCPlugin : public mjCPlugin_ {
friend class mjXWriter;
public:
mjCPlugin(mjCModel*);
explicit mjCPlugin(mjCModel*);
mjCPlugin(const mjCPlugin& other);
mjCPlugin& operator=(const mjCPlugin& other);
@@ -1689,7 +1689,7 @@ class mjCActuator : public mjCActuator_, private mjsActuator {
friend class mjXWriter;
public:
mjCActuator(mjCModel* = nullptr, mjCDef* = nullptr);
explicit mjCActuator(mjCModel* = nullptr, mjCDef* = nullptr);
mjCActuator(const mjCActuator& other);
mjCActuator& operator=(const mjCActuator& other);
@@ -1750,7 +1750,7 @@ class mjCSensor : public mjCSensor_, private mjsSensor {
friend class mjXWriter;
public:
mjCSensor(mjCModel*);
explicit mjCSensor(mjCModel*);
mjCSensor(const mjCSensor& other);
mjCSensor& operator=(const mjCSensor& other);
@@ -1791,7 +1791,7 @@ class mjCNumeric : public mjCNumeric_, private mjsNumeric {
friend class mjXWriter;
public:
mjCNumeric(mjCModel*);
explicit mjCNumeric(mjCModel*);
mjCNumeric(const mjCNumeric& other);
mjCNumeric& operator=(const mjCNumeric& other);
~mjCNumeric();
@@ -1823,7 +1823,7 @@ class mjCText : public mjCText_, private mjsText {
friend class mjXWriter;
public:
mjCText(mjCModel*);
explicit mjCText(mjCModel*);
mjCText(const mjCText& other);
mjCText& operator=(const mjCText& other);
~mjCText();
@@ -1860,7 +1860,7 @@ class mjCTuple : public mjCTuple_, private mjsTuple {
friend class mjXWriter;
public:
mjCTuple(mjCModel*);
explicit mjCTuple(mjCModel*);
mjCTuple(const mjCTuple& other);
mjCTuple& operator=(const mjCTuple& other);
~mjCTuple();
@@ -1904,7 +1904,7 @@ class mjCKey : public mjCKey_, private mjsKey {
friend class mjXWriter;
public:
mjCKey(mjCModel*);
explicit mjCKey(mjCModel*);
mjCKey(const mjCKey& other);
mjCKey& operator=(const mjCKey& other);
~mjCKey();
@@ -1930,7 +1930,7 @@ class mjCDef : public mjsElement {
public:
mjCDef();
mjCDef(mjCModel*);
explicit mjCDef(mjCModel*);
mjCDef(const mjCDef& other);
mjCDef& operator=(const mjCDef& other);
mjCDef& operator+=(const mjCDef& other);