C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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@

解决方法

我认为你必须对编译器的错误消息产生某种感觉.有更糟糕的,有更好的编译器.那个肯定是最糟糕的一个.一个好的指针将插入符号指向发生错误的位置,并提示可能出错的地方.

例如,在给定的情况下,编译器可能会在到达CP_M_ReferenceCounted时停止解析声明的类型,并将其解析为要声明的名称.语法允许,因为一些声明没有给出类型(构造函数一个例子).所以它期望该名称的初始化程序,而不是明星.这暗示可能未声明CP_M_ReferenceCounted.检查您是否包含正确的标题.

大佬总结

以上是大佬教程为你收集整理的c – 如何确定导致编译器错误的*真正*全部内容,希望文章能够帮你解决c – 如何确定导致编译器错误的*真正*所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。