Visualizzazione dei risultati da 1 a 5 su 5

Discussione: [c++]static

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++]static

    ciao,
    ho una funzione :
    codice:
     void MaterialTextureConnections( tag_INT_MATERIAL* pMat, KFbxSurfaceMaterial* pMaterial)
    {
    	KFbxProperty lProperty;
    
        //Diffuse Textures
        lProperty = pMaterial->FindProperty((char const*)KFbxSurfaceMaterial::sDiffuse);
    	pMat->m_strDiffuseTexture =  GetTexturesName(&lProperty);
    }
    quando hoprovato a crearla, inserendo il pMaterial->FindProperty, vuole che sia statica, e quindi l'ho dichiarata statica:
    codice:
    static void MaterialTextureConnections(tag_INT_MATERIAL* pMat, KFbxSurfaceMaterial* pMaterial);
    il problema è che se la invoco dall'interno della classe da una funzione non statica mi da il seguente errore:
    Error 14 error LNK2001: unresolved external symbol "public: static char const * const fbxsdk_2011_3::KFbxSurfaceMaterial::sDiffuse" (?sDiffuse@KFbxSurfaceMaterial@fbxsdk_2011_3@@2PBD B) FbxLoader.obj

    come si gestisce una funzione statica in questo caso?
    da quello che ho letto su google una funzione statica ha accesso solo a membri statici e non a membri non statici di classe ,non ha stato ,e non è possibile utilizzare this, ma non so proprio come procedere.

    grazie.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    questa se puo servire è la classe incriminata ,ho un costruttore protetto , perchè protetto?
    codice:
    #include <fbxfilesdk/fbxfilesdk_def.h>
    
    #include <fbxfilesdk/kfbxplugins/kfbxobject.h>
    #include <fbxfilesdk/kfbxplugins/kfbxcolor.h>
    #include <fbxfilesdk/kfbxplugins/kfbxgroupname.h>
    
    // FBX namespace
    #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
    
    /** This class contains material settings.
      * \nosubgrouping
      */
    class KFBX_DLL KFbxSurfaceMaterial : public KFbxObject
    {
    	KFBXOBJECT_DECLARE(KFbxSurfaceMaterial, KFbxObject);
    
    public:
    	/**
    	  * \name Standard Material Property Names
    	  */
    	//@{	
    
    	static char const* sShadingModel;
    	static char const* sMultiLayer;
    	
    	static char const* sEmissive;
    	static char const* sEmissiveFactor;
    	
    	static char const* sAmbient;
    	static char const* sAmbientFactor;
    	
    	static char const* sDiffuse;
    	static char const* sDiffuseFactor;
    	
    	static char const* sSpecular;
    	static char const* sSpecularFactor;
    	static char const* sShininess;
    	
    	static char const* sBump;
    	static char const* sNormalMap;
        static char const* sBumpFactor;
    
    	static char const* sTransparentColor;
    	static char const* sTransparencyFactor;
    	
    	static char const* sReflection;
    	static char const* sReflectionFactor;
    
        static char const* sDisplacementColor;
        static char const* sDisplacementFactor;
    
    	//@}	
    
    	/**
    	  * \name Material Properties
    	  */
    	//@{	
    	
    	/** Returns the material shading model.
    	  * \return The shading model.
    	  */
    	KFbxPropertyString GetShadingModel() const;
    
    	/**	Returns the multilayer state.
    	  * \return The state of the multi-layer flag.
    	  */
    	KFbxPropertyBool1 GetMultiLayer() const;
    	
    	//@}	
    
    	//////////////////////////////////////////////////////////////////////////
    	// Static values
    	//////////////////////////////////////////////////////////////////////////
    
    	/**
    	  * \name Default property values
    	  */
    	//@{
    
    	static fbxBool1		sMultiLayerDefault;
    	static char const*	sShadingModelDefault;
    
        //@}
    
    ///////////////////////////////////////////////////////////////////////////////
    //
    //  WARNING!
    //
    //	Anything beyond these lines may not be documented accurately and is 
    // 	subject to change without notice.
    //
    ///////////////////////////////////////////////////////////////////////////////
    #ifndef DOXYGEN_SHOULD_SKIP_THIS
    
    	// Clone
    	virtual KFbxObject* Clone(KFbxObject* pContainer, KFbxObject::ECloneType pCloneType = eDEEP_CLONE) const;
    
    protected:
    	bool SetColorParameter(KFbxProperty pProperty, KFbxColor const& pColor);
    	bool GetColorParameter(KFbxProperty pProperty, KFbxColor& pColor) const;
    	bool SetDoubleParameter(KFbxProperty pProperty, double pDouble);
    	bool GetDoubleParameter(KFbxProperty pProperty, double pDouble) const;
    	
    	KFbxSurfaceMaterial(KFbxSdkManager& pManager, char const* pName);
    
    	virtual bool ConstructProperties(bool pForceSet);
    
    public:
    	// From KFbxObject
    	virtual KString		GetTypeName() const;
    
    protected:
    	KFbxPropertyString ShadingModel;
    	KFbxPropertyBool1 MultiLayer;
    
    	friend class KFbxLayerContainer;
    #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 
    };
    
    typedef KFbxSurfaceMaterial* HKFbxSurfaceMaterial;
    
    #include <fbxfilesdk/fbxfilesdk_nsend.h>
    
    #endif // FBXFILESDK_KFBXPLUGINS_KFBXSURFACEMATERIAL_H

  3. #3
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Una funzione statica non è diversa da una funzione classica. Cambia il tipo di linkage (C++ ovviamente), esiste solo se preceduta dal nome della classe o struttura di appartenza, ma il comportamento è uguale a una normale funzione.
    Nel tuo caso, se non hai messo:
    codice:
    void KFbxSurfaceMaterial::MaterialTextureConnections (/*parametri*/)
    (con il KFBX_DLL tra il void e il nome della classe probabilmente), il linker non trova la signature corretta della funzione e segnala errore.
    Se invece l'hai dichiarata e definita all'interno della classe stessa, c'è altro in gioco.

    Un costruttore viene protetto quando non si vuole che l'utente possa istanziare la classe direttamente, ma solo attraverso un metodo (static ovviamente), oppure una funzione e/o classe friend (tipicamente una factory). In questo caso attraverso KFbxLayerContainer, probabilmente.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    mi sspiace se rompo , ma devo capire perchè non funziona anche se so che per te è molto difficile aiutarmi con poche spiegazioni.
    la classe che ti ho postato è relativa al pMaterial che è di tipo KFbxSurfaceMaterial con relativa classe che ho postato.
    la funzione
    codice:
    void  KFBX_DLL CFbxLoader::MaterialTextureConnections( tag_INT_MATERIAL* pMat, KFbxSurfaceMaterial* pMaterial)
    {
    	KFbxProperty lProperty;
    
    	//////Diffuse Textures
    	lProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse);
    .
    .
    .
    }
    che è interna alla mia classe CFbxLoader
    non ha problemi se commento la linea

    lProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse);

    ma se la uncommento: becco quest' errore:
    Error 1 error LNK2001: unresolved external symbol "public: static char const * const fbxsdk_2011_3::KFbxSurfaceMaterial::sDiffuse" (?sDiffuse@KFbxSurfaceMaterial@fbxsdk_2011_3@@2PBD B) FbxLoader.obj

    e non capisco.
    scusa se mi sono spiegato male.
    ciao

  5. #5
    Originariamente inviato da giuseppe500

    ma se la uncommento: becco quest' errore:
    Error 1 error LNK2001: unresolved external symbol "public: static char const * const fbxsdk_2011_3::KFbxSurfaceMaterial::sDiffuse" (?sDiffuse@KFbxSurfaceMaterial@fbxsdk_2011_3@@2PBD B) FbxLoader.obj

    e non capisco.
    scusa se mi sono spiegato male.
    ciao
    devi definire il membro statico (tipicamente in un cpp):
    codice:
    char const* KFbxSurfaceMaterial::sDiffuse = "pinco pallino" // o altro valore d'inizializzazione;

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 © 2024 vBulletin Solutions, Inc. All rights reserved.