Я переношу очень большую базу кода, и у меня возникают большие трудности со старым кодом.
Например, это вызывает ошибку компилятора:
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
eachClass FrReferenceIfClass(FxRC * ptr)
{
eachClass getObject = dynamic_cast(ptr);
if (getObject) getObject->AddReference();
return getObject;
}
Ошибка: ошибка: объявление шаблона '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
inline const T* CP_Autorelease(const T* inObj)
{
if( inObj )
inObj->Autorelease();
return( inObj );
}
template
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 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& inRef )
: fObj(inRef.fObj) { if( fObj ) fObj->AddReference(); }
template
CP_SmartRef( const CP_SmartRef& 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& operator = ( const CP_SmartRef& inRef ) { this->Reset( inRef.fObj ); return *this; }
template
CP_SmartRef& operator = ( const CP_SmartRef& inRef ) { this->Reset( inRef.Get() ); return *this; }
CP_SmartRef& operator = ( T* inObj ) { this->Reset( inObj ); return *this; }
template
CP_SmartRef& 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
T* CP_SmartRef::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
T* CP_SmartRef::Release()
{
T *tmp = fObj;
fObj = NULL;
return( tmp );
}
CPLAT_End_Namespace_CPLAT
#endif // _H_CP_M_RefCounted
Подробнее здесь: https://stackoverflow.com/questions/250 ... iler-error
Как определить, что *действительно* вызывает ошибку компилятора? ⇐ C++
Программы на C++. Форум разработчиков
-
Anonymous
1729548964
Anonymous
Я переношу очень большую базу кода, и у меня возникают большие трудности со старым кодом.
Например, это вызывает ошибку компилятора:
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
eachClass FrReferenceIfClass(FxRC * ptr)
{
eachClass getObject = dynamic_cast(ptr);
if (getObject) getObject->AddReference();
return getObject;
}
Ошибка: ошибка: объявление шаблона '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
inline const T* CP_Autorelease(const T* inObj)
{
if( inObj )
inObj->Autorelease();
return( inObj );
}
template
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 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& inRef )
: fObj(inRef.fObj) { if( fObj ) fObj->AddReference(); }
template
CP_SmartRef( const CP_SmartRef& 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& operator = ( const CP_SmartRef& inRef ) { this->Reset( inRef.fObj ); return *this; }
template
CP_SmartRef& operator = ( const CP_SmartRef& inRef ) { this->Reset( inRef.Get() ); return *this; }
CP_SmartRef& operator = ( T* inObj ) { this->Reset( inObj ); return *this; }
template
CP_SmartRef& 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
T* CP_SmartRef::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
T* CP_SmartRef::Release()
{
T *tmp = fObj;
fObj = NULL;
return( tmp );
}
CPLAT_End_Namespace_CPLAT
#endif // _H_CP_M_RefCounted
Подробнее здесь: [url]https://stackoverflow.com/questions/2503739/how-do-determine-what-is-really-causing-your-compiler-error[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия