我正在移植一個非常龐大的代碼庫,並且在舊代碼中遇到了更多的困難。如何確定導致編譯器錯誤的*真* *
例如,這將導致一個編譯器錯誤:
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;
}
的錯誤是:錯誤:預期初始化之前 '*' 標記。
我怎麼知道這是什麼。我查了內聯成員函數,以確保我明白,我不認爲內聯是原因,但我不確定是什麼。
又如:
template <class eachClass>
eachClass FrReferenceIfClass(FxRC * ptr)
{
eachClass getObject = dynamic_cast<eachClass>(ptr);
if (getObject) getObject->AddReference();
return getObject;
}
的錯誤是:錯誤:模板聲明 'eachClass FrReferenceIfClass'
這是所有。我如何確定這是什麼?我承認模板生鏽。
UPDATE:
這裏是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
您使用的編譯器是什麼? – 2010-03-23 21:37:59
@Josh - XCode 3.2 1,但GCC 4.0 – 2010-03-23 21:42:00
@ML我不能相信在第二種情況下,這是整個編譯器錯誤輸出。聽起來更像是另一條消息的後續。 – 2010-03-23 22:04:34