Muchas gracias a todos por vuestra ayuda. Aquí tenéis el dódigo donde se produce el error, así os será más fácil ayudarme:
// -----------------------------------------------------------------------
// CList.h: interface for the CList class
// -----------------------------------------------------------------------
#ifndef _CLIST_H_
#define _CLIST_H_
// -----------------------------------------------------------------------
// Includes
#include <stdlib.h>
#include <string.h>
// -----------------------------------------------------------------------
// Class definition
template <typename T> class CList
{
public:
#define ERASE_CALLBACK void (*CallBack)(T Content)
struct CList_Entry
{
struct CList_Entry *Next;
struct CList_Entry *Previous;
T Content;
};
// Default Constructor/Destructor
CList()
{
Free_Content = 0;
Nbr_Entries = 0;
Last_Entry = 0;
First_Entry = 0;
}
~CList()
{
this->Erase();
}
void Erase(ERASE_CALLBACK = NULL)
{
CList_Entry *Entry_To_Free;
// Take first entry in the list
Entry_To_Free = this->First_Entry;
while(Entry_To_Free)
{
First_Entry = Entry_To_Free->Next;
if(CallBack)
{
CallBack(Entry_To_Free->Content);
}
Del(Entry_To_Free);
Entry_To_Free = First_Entry;
}
}
int Amount(void)
{
return(Nbr_Entries);
}
CList_Entry *Add(T Datas, int Size)
{
CList_Entry *New_Entry = Create_Entry(Size);
Set(New_Entry, Datas, Size);
return(New_Entry);
}
template<typename T> CList_Entry *Add(T Datas)
{
CList_Entry *New_Entry = Create_Entry(0);
Set(New_Entry, Datas);
return(New_Entry);
}
template< > CList_Entry *Add<char *>(char *Datas)
{
int Size = strlen(Datas) + 1;
CList_Entry *New_Entry = Create_Entry(Size);
Set(New_Entry, Datas, Size);
return(New_Entry);
}
void MAdd(int Number, T Datas)
{
while(Number)
{
Add(Datas);
Number--;
}
}
CList_Entry *Set(int Entry_Number, T Datas)
{
CList_Entry *Entry_To_Set = Get(Entry_Number);
Set(Entry_To_Set, Datas);
return(Entry_To_Set);
}
template<typename T> CList_Entry *Set(CList_Entry *Entry_To_Set, T Datas)
{
Entry_To_Set->Content = (T) Datas; -----Esta es la línea del error
return(Entry_To_Set);
}
template< > CList_Entry *Set<char *>(CList_Entry *Entry_To_Set, char *Datas)
{
return(Set(Entry_To_Set, Datas, strlen(Datas) + 1));
}
CList_Entry *Set(int Entry_Number, T Datas, int Size)
{
CList_Entry *Entry_To_Set = Get(Entry_Number);
Set(Entry_To_Set, Datas, Size);
return(Entry_To_Set);
}
CList_Entry *Set(CList_Entry *Entry_To_Set, T Datas, int Size)
{
free((void *) Entry_To_Set->Content);
Entry_To_Set->Content = (T) calloc(Size, 1);
memcpy((void *) Entry_To_Set->Content, (void *) Datas, Size);
Free_Content = 1;
return(Entry_To_Set);
}
CList_Entry *Get(CList_Entry *Entry_To_Get)
{
CList_Entry *Current_Entry;
Current_Entry = this->First_Entry;
while(Current_Entry != Entry_To_Get)
{
Current_Entry = Current_Entry->Next;
}
return(Current_Entry);
}
CList_Entry *Get(int Entry_Number)
{
CList_Entry *Entry_To_Get;
Entry_To_Get = First_Entry;
while(Entry_Number)
{
Entry_To_Get = Entry_To_Get->Next;
Entry_Number--;
}
return(Entry_To_Get);
}
void Del(CList_Entry *Entry_To_Delete)
{
CList_Entry *Previous_Entry;
CList_Entry *Next_Entry;
if(!First_Entry)
{
Nbr_Entries = 0;
Last_Entry = 0;
First_Entry = 0;
return;
}
// First will be next
if(First_Entry == Entry_To_Delete) First_Entry = Entry_To_Delete->Next;
// Last will be previous
if(Last_Entry == Entry_To_Delete) Last_Entry = Entry_To_Delete->Previous;
// Get next/previous entries
Previous_Entry = Entry_To_Delete->Previous;
Next_Entry = Entry_To_Delete->Next;
if(Free_Content)
{
free((void *) Entry_To_Delete->Content);
}
free(Entry_To_Delete);
// Update previous/next entries
if(Next_Entry) Next_Entry->Previous = Previous_Entry;
if(Previous_Entry) Previous_Entry->Next = Next_Entry;
if(this->Nbr_Entries) this->Nbr_Entries--;
}
};
#endif
Gracias de nuevo a todos, ahora comprobaré vuestas aportaciones. La línea que produce el error tiene una nota en rojo
ipadilla
Lh: No hagas doble post, usa el botón modificar.
Hola a todos,
pues no logro eliminar el error, me podéis porner un ejemplo ahora que teneis el código.
Muchas gracias
ipadilla
Hola Littlehorse,
Alleluya!!!, he encontrado el botón modificar, perdón por mi torpeza.
He probado las propuestas que me han hecho en este foro, pero no he logrado que me funcione. Posiblemente no lo hago bien. ¿Me podrías explecar cono realizar un casteo seguro, ahora que dispones del código?. Si necesitas algo más me lo puedes pedir.
gracias y saludos
iapdilla
// -----------------------------------------------------------------------
// CList.h: interface for the CList class
// -----------------------------------------------------------------------
#ifndef _CLIST_H_
#define _CLIST_H_
// -----------------------------------------------------------------------
// Includes
#include <stdlib.h>
#include <string.h>
// -----------------------------------------------------------------------
// Class definition
template <typename T> class CList
{
public:
#define ERASE_CALLBACK void (*CallBack)(T Content)
struct CList_Entry
{
struct CList_Entry *Next;
struct CList_Entry *Previous;
T Content;
};
// Default Constructor/Destructor
CList()
{
Free_Content = 0;
Nbr_Entries = 0;
Last_Entry = 0;
First_Entry = 0;
}
~CList()
{
this->Erase();
}
void Erase(ERASE_CALLBACK = NULL)
{
CList_Entry *Entry_To_Free;
// Take first entry in the list
Entry_To_Free = this->First_Entry;
while(Entry_To_Free)
{
First_Entry = Entry_To_Free->Next;
if(CallBack)
{
CallBack(Entry_To_Free->Content);
}
Del(Entry_To_Free);
Entry_To_Free = First_Entry;
}
}
int Amount(void)
{
return(Nbr_Entries);
}
CList_Entry *Add(T Datas, int Size)
{
CList_Entry *New_Entry = Create_Entry(Size);
Set(New_Entry, Datas, Size);
return(New_Entry);
}
template<typename T> CList_Entry *Add(T Datas)
{
CList_Entry *New_Entry = Create_Entry(0);
Set(New_Entry, Datas);
return(New_Entry);
}
template< > CList_Entry *Add<char *>(char *Datas)
{
int Size = strlen(Datas) + 1;
CList_Entry *New_Entry = Create_Entry(Size);
Set(New_Entry, Datas, Size);
return(New_Entry);
}
void MAdd(int Number, T Datas)
{
while(Number)
{
Add(Datas);
Number--;
}
}
CList_Entry *Set(int Entry_Number, T Datas)
{
CList_Entry *Entry_To_Set = Get(Entry_Number);
Set(Entry_To_Set, Datas);
return(Entry_To_Set);
}
template<typename T> CList_Entry *Set(CList_Entry *Entry_To_Set, T Datas)
{
Entry_To_Set->Content = (T) Datas; -----Esta es la línea del error
return(Entry_To_Set);
}
template< > CList_Entry *Set<char *>(CList_Entry *Entry_To_Set, char *Datas)
{
return(Set(Entry_To_Set, Datas, strlen(Datas) + 1));
}
CList_Entry *Set(int Entry_Number, T Datas, int Size)
{
CList_Entry *Entry_To_Set = Get(Entry_Number);
Set(Entry_To_Set, Datas, Size);
return(Entry_To_Set);
}
CList_Entry *Set(CList_Entry *Entry_To_Set, T Datas, int Size)
{
free((void *) Entry_To_Set->Content);
Entry_To_Set->Content = (T) calloc(Size, 1);
memcpy((void *) Entry_To_Set->Content, (void *) Datas, Size);
Free_Content = 1;
return(Entry_To_Set);
}
CList_Entry *Get(CList_Entry *Entry_To_Get)
{
CList_Entry *Current_Entry;
Current_Entry = this->First_Entry;
while(Current_Entry != Entry_To_Get)
{
Current_Entry = Current_Entry->Next;
}
return(Current_Entry);
}
CList_Entry *Get(int Entry_Number)
{
CList_Entry *Entry_To_Get;
Entry_To_Get = First_Entry;
while(Entry_Number)
{
Entry_To_Get = Entry_To_Get->Next;
Entry_Number--;
}
return(Entry_To_Get);
}
void Del(CList_Entry *Entry_To_Delete)
{
CList_Entry *Previous_Entry;
CList_Entry *Next_Entry;
if(!First_Entry)
{
Nbr_Entries = 0;
Last_Entry = 0;
First_Entry = 0;
return;
}
// First will be next
if(First_Entry == Entry_To_Delete) First_Entry = Entry_To_Delete->Next;
// Last will be previous
if(Last_Entry == Entry_To_Delete) Last_Entry = Entry_To_Delete->Previous;
// Get next/previous entries
Previous_Entry = Entry_To_Delete->Previous;
Next_Entry = Entry_To_Delete->Next;
if(Free_Content)
{
free((void *) Entry_To_Delete->Content);
}
free(Entry_To_Delete);
// Update previous/next entries
if(Next_Entry) Next_Entry->Previous = Previous_Entry;
if(Previous_Entry) Previous_Entry->Next = Next_Entry;
if(this->Nbr_Entries) this->Nbr_Entries--;
}
};
#endif
Gracias de nuevo a todos, ahora comprobaré vuestas aportaciones. La línea que produce el error tiene una nota en rojo
ipadilla
Lh: No hagas doble post, usa el botón modificar.
Hola a todos,
pues no logro eliminar el error, me podéis porner un ejemplo ahora que teneis el código.
Muchas gracias
ipadilla
Hola Littlehorse,
Alleluya!!!, he encontrado el botón modificar, perdón por mi torpeza.
He probado las propuestas que me han hecho en este foro, pero no he logrado que me funcione. Posiblemente no lo hago bien. ¿Me podrías explecar cono realizar un casteo seguro, ahora que dispones del código?. Si necesitas algo más me lo puedes pedir.
gracias y saludos
iapdilla