大佬教程收集整理的这篇文章主要介绍了c – 如何确定导致编译器错误的*真正*,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
例如,这会导致编译器错误:
inline CP_M_ReferenceCounted * FrAssignRef(CP_M_ReferenceCounted * & to,CP_M_ReferenceCounted * from) { if (from) from->AddReference(); if (to) to->RemoveReference(); to = from; return to; }@H_772_10@我怎么知道这是什么我查找了内联成员函数,以确保我理解,我不认为内联是原因,但我不确定是什么.
另一个例子:
template <class eachClass> eachClass FrReferenceIfClass(FxRC * ptr) { eachClass getObject = dynamic_cast<eachClass>(ptr); if (getObject) getObject->AddReference(); return getObject; }@H_772_10@错误是:错误:’eachClass FrReferenceIfClass’的模板声明
就这些.我该如何判断这是什么?我确实生锈了模板.
更新:
这是CP_M_ReferenceCounted:
#pragma once #ifndef _H_CP_M_RefCounted #define _H_CP_M_RefCounted // CPLAT_Framework #include "CP_Types.h" CPLAT_Begin_Namespace_CPLAT /*! * @class CP_M_RefCounted * @brief Mix-in class for objects that are reference counted. */ class CP_EXPORT CP_M_RefCounted { public: //! @name Reference //@{ UInt32 AddReference() const; UInt32 RemoveReference() const; //@} //! @name Autorelease //@{ void Autorelease() const; //@} //! @name Getters //@{ /*! * Returns the current ref count. * * @exception none * * @return UInt32 The current referencce count. */ UInt32 GetRefCount() const { return( fRefCount ); } //@} //! @name operators //@{ CP_M_RefCounted& operator = ( const cP_M_RefCounted& inRefCounted ); //@} protected: //! @name Constructor / Destructor //@{ //! Constructor. CP_M_RefCounted(); CP_M_RefCounted( CP_M_RefCounted& inRefCounted ); //! Destructor. virtual ~CP_M_RefCounted(); //@} // class data private: mutable UInt32 fRefCount; /*! the number of references to this object. */ //======================================================================== // Platform specific routInes //======================================================================== #if TARGET_OS_MAC #endif #if TARGET_OS_WIN32 #endif #if TARGET_OS_LINUX #endif }; template <class T> inline const T* CP_Autorelease(const T* inObj) { if( inObj ) inObj->Autorelease(); return( inObj ); } template <class T> inline T* CP_Autorelease(T* inObj) { if( inObj ) inObj->Autorelease(); return( inObj ); } /*! * @class CP_smartRef * @brief Template class represenTing a smart pointer for reference counted objects. */ template <class T> class CP_smartRef { public: //! @name Constructor / Destructor //@{ //! Constructor. CP_smartRef() : fObj(NULL) {} CP_smartRef( T *inObj,bool inTransferownership=false ) : fObj(inObj) { if( !inTransferownership && fObj ) fObj->AddReference(); } CP_smartRef( const cP_smartRef<T>& inRef ) : fObj(inRef.fObj) { if( fObj ) fObj->AddReference(); } template <class Other> CP_smartRef( const cP_smartRef<Other>& inRef ) : fObj(NULL) { T* other = inRef.Get(); this->Reset( other ); } // assignment to local variable should prevent upcasts and cross-casts //! Destructor. ~CP_smartRef() { if( fObj ) fObj->RemoveReference(); } //@} //! @name operators //@{ T& operator *() const { return( *fObj ); } T* operator->() const { return( fObj ); } operator T *() const { return( fObj ); } CP_smartRef<T>& operator = ( const cP_smartRef<T>& inRef ) { this->Reset( inRef.fObj ); return *this; } template <class Other> CP_smartRef<T>& operator = ( const cP_smartRef<Other>& inRef ) { this->Reset( inRef.Get() ); return *this; } CP_smartRef<T>& operator = ( T* inObj ) { this->Reset( inObj ); return *this; } template <class Other> CP_smartRef<T>& operator = ( Other* inObj ) { this->Reset( inObj ); return *this; } //@} //! @name Object management //@{ T *Get() const { return( fObj ); } T *Reset( T *inObj,bool inTransferownership = false ); T *Release(); //@} // class data protected: T *fObj; //======================================================================== // Platform specific routInes //======================================================================== #if TARGET_OS_MAC #endif #if TARGET_OS_WIN32 #endif #if TARGET_OS_LINUX #endif }; template <class T> T* CP_smartRef<T>::reset( T *inObj,bool inTransferownership ) { if ( inObj != fObj ) { if( fObj ) fObj->RemoveReference(); fObj = inObj; if( inObj && !inTransferownership ) inObj->AddReference(); } else if( inObj && inTransferownership ) { inObj->RemoveReference(); } return( fObj ); } template <class T> T* CP_smartRef<T>::release() { T *tmp = fObj; fObj = NULL; return( tmp ); } CPLAT_End_Namespace_CPLAT #endif // _H_CP_M_RefCounted@H_772_10@
以上是大佬教程为你收集整理的c – 如何确定导致编译器错误的*真正*全部内容,希望文章能够帮你解决c – 如何确定导致编译器错误的*真正*所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。