Thread: never seen a type *fnc (params); before, need clarification on use

  1. #1
    Registered User daluu's Avatar
    Join Date
    Dec 2002
    Posts
    42

    never seen a type *fnc (params); before, need clarification on use

    I've never seen something like:
    Code:
    class IdClass {
      public:
        IdClass();			// initialize the list
        ~IdClass();			// de-allocate the list
    
        void Add (void *item, int Key);	// Put item into list
        void *Remove (int Key);
      private:
        IdElement *first;  	// Head of the list, NULL if list is empty
        IdElement *last;		// Last element of list
    };
    
    void * IdClass::Remove (int a)
    {
      IdElement * tmp = first, * prev = (IdElement *)NULL;
      while ((tmp != NULL) && (tmp->key != a))
      {
        prev = tmp;
        tmp = tmp->next;
      }
      //more code in function here
      return value;
    }
    How do I use the Remove function if I'm instantiating an instance like this:
    Code:
    IdClass *test;
    test = new IdClass();
    
    //for add I can do this
    test->Add(itemptr,5);
    I don't know how to call Remove. I've never seen that syntax before. And what does that syntax mean?

  2. #2
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    void *Remove (int Key);
    a function that takes an int and returns a void pointer. in c++ you need to cast the return value to the needed type, i think, not sure
    :wq

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Code:
    int main()
    {
      ....
      test.Remove(5);
      ....
    }
    >>I've never seen that syntax before. And what does that syntax mean?

    what part of the which syntax don't you understand?

  4. #4
    Registered User daluu's Avatar
    Join Date
    Dec 2002
    Posts
    42
    thanks for the info. and from that info, if "test" was not a pointer to the instance but rather the instance itself, the call to Remove would be

    Code:
    test->Remove(5);
    right?

    I didn't realize the function was returning a pointer of the type, so I didn't know what was the purpose of defining the function that way. Now I know. thanks.
    Last edited by daluu; 12-02-2004 at 01:21 PM.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    My bad.

    test.Remove(5); if test is an object and
    test->Remove(5); if test is a pointer to an object.

    Sorry. Didn't register in my noggin that test was declared dynamicaly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM