Anyone can help me ?
-
The below is GList.H
#ifndef __GLIST_H
#define __GLIST_H#include
#include
#include
#include
#include
#includetypedef enum bool { false, true};
/* -------------------- Define class GList ----------------- */
class GList
{
private:
char **arr;
int length;
void FillEmptyAll(int);
void ResizeList(int);
void SetArr(char **);
void SetLen(size_t);
char **GetArr() { return arr; }public:
size_t GetLen();
void Add(const char*);
void Add(String);
void SetValue(size_t, const char*);
void SetValue(size_t, String);
char* GetValue(size_t);
void InsertValue(size_t, const char*);
void InsertValue(size_t, String);
void FillEmptyRange(size_t, size_t);
void CreateMemList(size_t);
// void ResizeMemList(int);
void RemoveAt(size_t);
void RemoveRange(size_t, size_t);
void RemoveValue(const char *);
void RemoveValue(String);
void RemoveAllValue(const char *);
void RemoveAllValue(String);GList(); GList(const GList& L); //Copy constructor //GList(const GList\* &L); GList& operator=(const GList& L); //assignment operator = //GList& operator=(const GList\* &L); virtual ~GList();
};
/* Constructor */
inline GList::GList(void)
{
length = 1;
arr = (char**) malloc(sizeof(char*) * length);
//arr = NULL;
}/* Define Copy Constructor */
inline GList::GList(const GList& L): length(L.length),
arr((char**)malloc(sizeof(char*) * L.length))
{
int idx = L.length - 1;
for(int i = 0; i < idx; i++){
*(arr + i) = *(L.arr + i);
}
*(arr + idx) = 0;
}/* Define operator = */
inline GList& GList::operator=(const GList& L)
{
if (this == &L) return *this;
else
{
length = L.length;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = (char**)malloc(sizeof(char*) * L.length);
int idx = L.length - 1;
for(int i = 0; i < idx; i++)
*(arr + i) = *(L.arr + i);\*(arr + idx) = 0;
}
return *this;
}/* Destructor */
inline GList::~GList()
{
if (arr != 0)
{
free(arr);
//arr = NULL;
}
printf("Destructor GList");
}/* -------------- Define Property for GList ------------*/
/* Fill All Value in arr = "" ----------- */
void GL -
The below is GList.H
#ifndef __GLIST_H
#define __GLIST_H#include
#include
#include
#include
#include
#includetypedef enum bool { false, true};
/* -------------------- Define class GList ----------------- */
class GList
{
private:
char **arr;
int length;
void FillEmptyAll(int);
void ResizeList(int);
void SetArr(char **);
void SetLen(size_t);
char **GetArr() { return arr; }public:
size_t GetLen();
void Add(const char*);
void Add(String);
void SetValue(size_t, const char*);
void SetValue(size_t, String);
char* GetValue(size_t);
void InsertValue(size_t, const char*);
void InsertValue(size_t, String);
void FillEmptyRange(size_t, size_t);
void CreateMemList(size_t);
// void ResizeMemList(int);
void RemoveAt(size_t);
void RemoveRange(size_t, size_t);
void RemoveValue(const char *);
void RemoveValue(String);
void RemoveAllValue(const char *);
void RemoveAllValue(String);GList(); GList(const GList& L); //Copy constructor //GList(const GList\* &L); GList& operator=(const GList& L); //assignment operator = //GList& operator=(const GList\* &L); virtual ~GList();
};
/* Constructor */
inline GList::GList(void)
{
length = 1;
arr = (char**) malloc(sizeof(char*) * length);
//arr = NULL;
}/* Define Copy Constructor */
inline GList::GList(const GList& L): length(L.length),
arr((char**)malloc(sizeof(char*) * L.length))
{
int idx = L.length - 1;
for(int i = 0; i < idx; i++){
*(arr + i) = *(L.arr + i);
}
*(arr + idx) = 0;
}/* Define operator = */
inline GList& GList::operator=(const GList& L)
{
if (this == &L) return *this;
else
{
length = L.length;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = (char**)malloc(sizeof(char*) * L.length);
int idx = L.length - 1;
for(int i = 0; i < idx; i++)
*(arr + i) = *(L.arr + i);\*(arr + idx) = 0;
}
return *this;
}/* Destructor */
inline GList::~GList()
{
if (arr != 0)
{
free(arr);
//arr = NULL;
}
printf("Destructor GList");
}/* -------------- Define Property for GList ------------*/
/* Fill All Value in arr = "" ----------- */
void GLFirst of all, please remember the debugging 101: 1. Attach a debugger and try to run it then. 2. The debugger will stop at the Null Pointer assignement, and you can fix the error. About Null pointer assignments: Null pointer assignments occur when you try to access a pointer which's memory was deleted or not initialized (via malloc or new) and are a strong hint towards dangling and insecure pointers.
People becoming wiser in order to notice the stupid things they did back in the young days. This doesn't mean that they really stop doing those things. Wise people still do stupid things, only on purpose.