Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Anyone can help me ?

Anyone can help me ?

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gecko2k1
    wrote on last edited by
    #1

    The below is GList.H

    #ifndef __GLIST_H
    #define __GLIST_H

    #include
    #include
    #include
    #include
    #include
    #include

    typedef 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

    M 1 Reply Last reply
    0
    • G gecko2k1

      The below is GList.H

      #ifndef __GLIST_H
      #define __GLIST_H

      #include
      #include
      #include
      #include
      #include
      #include

      typedef 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

      M Offline
      M Offline
      Marco Bertschi
      wrote on last edited by
      #2

      First 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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups