reference object

This is a discussion on reference object within the C++ Programming forums, part of the General Programming Boards category; >> It shouldn't create a circular list... It does. >> as I nullify the tmp pointer... That does nothing. >> ...

  1. #16
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    >> It shouldn't create a circular list...
    It does.

    >> as I nullify the tmp pointer...
    That does nothing.

    >> The problem still exists...
    I've already explained all the problems with what you posted. If you want the rest of your problems fixed, then post (or zip up and attach) enough code that will compile and run to demonstrate the issue.

    gg

  2. #17
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    Wink

    Thanx. The code is attached.
    Attached Files Attached Files

  3. #18
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,674
    There is no crash in tstg.cpp, it inserted 3 things and displayed 3 things and all the memory was deleted properly.

    >> bool operator==(dbase &op2);
    >> dbase& operator=(dbase &op2);
    Use references for these.

    >> friend void initialiseList(dbase &list);
    >> friend bool listIsEmpty(dbase &list);
    >> friend void displayList(dbase &list);
    >> friend void insertIntoList(dbase &list, char *name, int age, int number);
    Why not just make these member functions of dbase?

    >> return (name == op2.name && age == op2.age && phone == op2.phone);
    This just compares memory addresses, the strings themselves are never compared.

    >> while ((iterator->link != NULL) && (iterator->name < name))
    >> if ((iterator->name < name) && (iterator->link == NULL))
    These are just comparing memory addresses, the strings themselves are never compared.

    >> if (*iterator->name > *name)
    We already know what this is doing...

    >> tmp->link = &list;
    >> list = *tmp;
    We already know what's wrong with this as well...

    Use std::string instead of c-strings and you can get rid of the copy constructor and overloaded = operator. You can use ==, <, and > on std::string's. Otherwise, you'll have to use strcmp() to compare strings correctly.

    gg

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to maintain and return local object reference?
    By benshi in forum C++ Programming
    Replies: 14
    Last Post: 12-16-2007, 01:17 PM
  2. Managing a reference object
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 11-23-2006, 06:41 PM
  3. Question about OpenGL/Linux
    By Ideswa in forum Linux Programming
    Replies: 12
    Last Post: 09-10-2006, 05:56 AM
  4. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  5. Beginners guide to OOP from a Java background?!
    By eggsy84 in forum C++ Programming
    Replies: 6
    Last Post: 06-08-2005, 06:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21