Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++]costruttori protetti

    ciao.
    ho la seguente classe:
    codice:
    class IFC2X3_DLL_DEF IfcObjectPlacement : public Step::BaseEntity {
        public:
            /**
             * Accepts a read/write Step::BaseVisitor.
             * 
             * @param visitor the read/write Step::BaseVisitor to accept
             */
            virtual bool acceptVisitor(Step::BaseVisitor *visitor);
            /**
             * Returns the class type as a human readable std::string.
             * 
             */
            virtual const std::string &type() const;
            /**
             * Returns the Step::ClassType of this specific class. Useful to compare with the isOfType method for example.
             * 
             */
            static const Step::ClassType &getClassType();
            /**
             * Returns the Step::ClassType of the instance of this class. (might be a subtype since it is virtual and overloaded).
             * 
             */
            virtual const Step::ClassType &getType() const;
            /**
             * Compares this instance's Step::ClassType with the one passed as parameter. Checks the type recursively (to the mother classes).
             * 
             * @param t
             */
            virtual bool isOfType(const Step::ClassType &t) const;
            /**
             * Gets the value of the inverse attribute 'PlacesObject'.
             * MM 2009/09/07 change to correct a bug that will be resolved in 2x4
             */
            Inverse_Set_IfcProduct_1_n &getPlacesObject();
            /**
             * (const) Returns the value of the explicit attribute 'PlacesObject'.
             * 
             * @return the value of the explicit attribute 'PlacesObject'
             */
            virtual const Inverse_Set_IfcProduct_1_n &getPlacesObject() const;
            /**
             * Test if the attribute 'PlacesObject' is set.
             * MM 2009/09/07 change to correct a bug that will be resolved in 2x4
             * @return true if set, false if unset
             */
            virtual bool testPlacesObject() const;
            /**
             * Gets the value of the inverse attribute 'ReferencedByPlacements'.
             * 
             */
            Inverse_Set_IfcLocalPlacement_0_n &getReferencedByPlacements();
            /**
             * (const) Returns the value of the explicit attribute 'ReferencedByPlacements'.
             * 
             * @return the value of the explicit attribute 'ReferencedByPlacements'
             */
            virtual const Inverse_Set_IfcLocalPlacement_0_n &getReferencedByPlacements() const;
            /**
             * Test if the attribute 'ReferencedByPlacements' is set.
             * 
             * @return true if set, false if unset
             */
            virtual bool testReferencedByPlacements() const;
            friend class IfcLocalPlacement;
            friend class IfcProduct;
            friend class ExpressDataSet;
    
        protected:
            /**
             * @param id
             * @param args
             */
            IfcObjectPlacement(Step::Id id, Step::SPFData *args);
            virtual ~IfcObjectPlacement();
            /**
             */
            virtual bool init();
            /**
             * @param obj
             * @param copyop
             */
            virtual void copy(const IfcObjectPlacement &obj, const CopyOp &copyop);
    
        private:
            /**
             */
            static Step::ClassType s_type;
            /**
             * MM 2009/09/07 change to correct a bug that will be resolved in 2x4
             */
            Inverse_Set_IfcProduct_1_n m_placesObject;
            /**
             */
            Inverse_Set_IfcLocalPlacement_0_n m_referencedByPlacements;
    
        };
    quando dichiaro una variabile ad es in questa classe:

    codice:
    #pragma once
    #include <ifc2x3/ifc2x3DLL.h>
    #include <ifc2x3/IfcLocalPlacement.h>
    #include <ifc2x3/3DVectorIfc.h>
    #include <ifc2x3/3DMatrixIfc.h>
    #include <Step/BaseObject.h>
    
    
    class IFC2X3_DLL_DEF CIfcTrasformation
    {
    public:
    	CIfcTrasformation(void);
    	~CIfcTrasformation(void);
    	//ritorna la matrice di rotazione 3x3 e il vettore di translazione dal IfcLocalPlacement
    	int GetPositionAndRotation(const Step::RefPtr<ifc2x3::IfcLocalPlacement>& pPlacement, C3DVectorIfc& position, C3DMatrixIfc& matrix );
    	int MultiplyPositionForParent(const Step::RefPtr<ifc2x3::IfcLocalPlacement>& ParentPlacement);
    
    private:
    
    	ifc2x3::IfcLocalPlacement m_LocalPlacement; // oggetto che contiene matrici di rotazione e posizione
    	C3DVectorIfc m_Position; //vettore con translazione
    	C3DMatrixIfc m_RotationMatix;//matrice di rotazione
    
    };

    ifc2x3::IfcLocalPlacement m_LocalPlacement; // oggetto che contiene matrici di rotazione e posizione

    mi da questi errori:
    c:\ifc\project\src\ifc2x3\IfcTrasformation.cpp(15) : error C2248: 'ifc2x3::IfcLocalPlacement::~IfcLocalPlacement' : cannot access protected member declared in class 'ifc2x3::IfcLocalPlacement'
    C:\ifc\include\ifc2x3\IfcLocalPlacement.h(131) : see declaration of 'ifc2x3::IfcLocalPlacement::~IfcLocalPlacement'
    C:\ifc\include\ifc2x3\IfcLocalPlacement.h(38) : see declaration of 'ifc2x3::IfcLocalPlacement'
    c:\ifc\project\src\ifc2x3\IfcTrasformation.cpp(11) : error C2512: 'ifc2x3::IfcLocalPlacement' : no appropriate default constructor available


    come poso risolvere e a cosa servono i costruttori protetti?
    da quello che ho capito posso dichiarare una variabile o un puntatore solo all interno della gerarchia di ereditarietà di cui fa parte IfcLocalPlacement, ma perchè?

  2. #2

    Re: [c++]costruttori protetti

    Originariamente inviato da giuseppe500
    a cosa servono i costruttori protetti?
    da quello che ho capito posso dichiarare una variabile o un puntatore solo all interno della gerarchia di ereditarietà di cui fa parte IfcLocalPlacement, ma perchè?
    No, lo scopo non è quello di dichiarare una variabile o un puntatore all'interno della gerarchia ma è quello di creare oggetti che derivano da IfcLocalPlacement.
    Per esempio tu potrai creare oggetti A, B e C che derivano da IfcLocalPlacement, senza perdere i vantaggi del polimorfismo.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.