C++ std::映射分配错误:无法在赋值中将' type **'转换为'type *'
c++ std::map asignation error : cannot convert ' type **' to 'type *' in assignment
hi我正在尝试开发一个简单的类,它可以管理映射列表,该类使用模板。
#include <map>
template<class R, typename IDPK = int >
class ActivationList
{
public:
typedef R type_value;
typedef R* pointer_type_value;
typedef const R * const_point_type_value;
typedef R & reference_type;
typedef const R & const_reference_type;
typedef const IDPK & const_ref_ID_PK_value;
typedef const IDPK const_Type;
typedef R ** ptr_reference_Type;
/**
* @brief ActivationList constructor explicito de la luista de activacion
* @param aType primer mensaje para alojar en
* @param aIdPK identificador unico
*/
explicit ActivationList(pointer_type_value aType , const_ref_ID_PK_value aIdPK)
{
}
/**
* @brief setSize
* @param aSize
*/
void setSize(const int & aSize)
{
mSize=aSize;
}
/**
* @brief getSize
* @return
*/
int getSize() const
{
return this->mSize;
}
/**
* @brief isEmpty
* @return
*/
bool isEmpty() const
{
return this->mListMessage->empty();
}
/**
* @brief isFull
* @return
*/
bool isFull() const
{
return (mListMessage->size()==mSize);
}
/**
* @brief insertValuesInMapLis inserta valores dentro de la lista de activacion
* @param aType puntero al la estructura que se quiere guardar
* @param aIdPK primary Key para realizar asociacion de la estructura de mensaje con respecto al ID mensaje
* @return 0=OK, negativo lo contrario
*/
int insertValuesInMapLis(pointer_type_value aType , const_ref_ID_PK_value aIdPK)
{
if (!aType) return -1;
if (aIdPK<0) return -2;
mListMessage->insert(std::pair<const_ref_ID_PK_value, pointer_type_value>(aIdPK,aType));
return 0;
}
/**
* @brief findMessageId metdo que busca dentro de la lista de activacion segun una Primary Key
* @param aReferenceType valor donde se almacenara el valor buscado
* @param aPKValue valor de la primary key a buscar, en este caso caso el IDMensaje
* @param aResult resulta de la operacion, 0=OK, negativo de lo contrario
*/
void findMessageId(reference_type aReferenceType,const int & aPKValue, int & aResult)
{
if (aPKValue < 0) {
aResult=-1;
return;
}
//buscar valor dentro de la lista
mMessageListIterador=mListMessage->find(aPKValue);
if (mMessageListIterador!=mListMessage->end())
{
aResult=0;
aReferenceType=mMessageListIterador->second;
}
else aResult=-1;
return;
}
void findMessageId(R * aPointerType,const int & aPKValue, int & aResult)
{
if (aPKValue < 0) {
aResult=-1;
return;
}
//buscar valor dentro de la lista
mMessageListIterador=mListMessage->find(aPKValue);
if (mMessageListIterador!=mListMessage->end())
{
aResult=0;
aPointerType=&mMessageListIterador->second;
}
else aResult=-1;
return;
}
/**
* @brief push metodo que inserta un mensaje en la lista de activacion
* @param aType mensaje que se va a ingresar a la lista
* @param aIdPK identificador unico del mensaje . IDMessage
* @return 0=OK, negativo lo contrario
*/
int push(pointer_type_value aType , const_ref_ID_PK_value aIdPK )
{
return insertValuesInMapLis(aType ,aIdPK);
}
/**
* @brief pop metodo que extrae un mensaje de la pila
* @param aReferenceType valor donde se depositara el valor requerido
* @param aPKValue primary key del mensaje buscado = IDMensaje
* @param aResult 0=OK, negativo lo contrario
*
*/
void pop(reference_type aReferenceType,const int & aPKValue, int & aResult)
{
findMessageId(aReferenceType, aPKValue, aResult);
}
/**
* @brief cleanList metodo que eliminia todos los mensajes de la lista
*/
void cleanList()
{
mListMessage->clear();
}
/**
* @brief eraseMessage elimina un mensaje en particular
* @param aIDMessage identificador unico del mensaje
* @param aResult 0=OK, negativo lo contrario
*/
void eraseMessage(const int & aIDMessage, int & aResult)
{
aResult=-1;
mMessageListIterador=mListMessage->find(aIDMessage);
if (mMessageListIterador==mListMessage->end())
{
//eliminacion del mensaje
mListMessage->erase(aIDMessage);
aResult=0;
//
}
}
private:
ActivationList();
ActivationList(const ActivationList &);
const ActivationList & operator=(const ActivationList &);
std::map<const_Type, pointer_type_value > * mListMessage;
typename std::map<const_Type, pointer_type_value >::iterator mMessageListIterador;
int mSize;
};
然后,主要使用:
ActivationList<IMetodo,int> aActivationList(0,12);
aActivationList.push(aMessageQueue,1221);
//int aResultType=0;
IMetodo * aMethodPointer=0;
aActivationList.findMessageId(aMethodPointer,1221,aResul
编译器输出:
cannot convert 'IMetodo**' to 'IMetodo*' in assignment
我已经花了很多时间试图找出问题出在哪里,但我看不出是哪里。有人能帮忙吗?
void findMessageId(R * aPointerType,const int & aPKValue, int & aResult)
{
if (aPKValue < 0) {
aResult=-1;
return;
}
//buscar valor dentro de la lista
mMessageListIterador=mListMessage->find(aPKValue);
if (mMessageListIterador!=mListMessage->end())
{
aResult=0;
aPointerType=&mMessageListIterador->second;
}
else aResult=-1;
return;
}
在这种方法中,我更改了这一行:
aPointerType=&mMessageListIterador->second;
为此:
aPointerType=mMessageListIterador->second;
相关文章:
- 将内存分配返回值强制转换为 TYPE 数组
- C++ 嵌套类模板 错误 C2440 '=':无法从'type'转换为'same type'
- 为什么指针没有隐式转换为 <type> const*const
- 从整数到枚举的首选转换样式 QEvent::Type
- c++ C2440 错误无法从"const BWAPI::UpgradeType"转换为"const BWAPI::Type *"
- C++ 错误 C2662 无法将"this"指针从"const Type"转换为"Type &"
- 错误 C2440: 'type cast':无法从 'bool' 转换为 'CString'
- 无法将参数 1 从"cli::interior_ptr<Type>"转换为"CvCapture **"
- 将 MSVS 2010 项目转换为 MSVS 2012 RC,但出现错误"The C++ standard doesn't provide a hash for this type"
- 专用转换函数导致"ambiguous default type conversion"错误 (c++)
- vector::p ush_back 从 const Type* 转换为 type*
- 可以安全地使用静态强制转换,为每个实例使用唯一的虚拟 int type() 来提高性能
- 无法将参数 1 从"cli::array<Type> ^"转换为"无符号短整型"
- 无法从 Type* 转换为 Type&&
- 没有匹配的操作数[template]/无法从Type const*转换为Type
- C++ std::映射分配错误:无法在赋值中将' type **'转换为'type *'
- 错误 C2440 '=' : 无法从 'cli::array ^'<Type> 转换为 'wchar_t'
- 将Type**转换为void*,然后再返回到Type*
- 将 std::vector<const Type*> 转换为 const std::vector<T, A> &Vec
- 函数将变量Type转换为Type*,导致C++错误