Deleting Data within a Structure or class

This is a discussion on Deleting Data within a Structure or class within the C++ Programming forums, part of the General Programming Boards category; My apologies for no code. I have a question that I could not seem to find the answer to. I ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    37

    Deleting Data within a Structure or class

    My apologies for no code. I have a question that I could not seem to find the answer to.

    I currently have a program that enters data from the Keyboard into a structure. If I wanted to delete records once they were entered into the structure:

    1) How would this be accomplished?
    Search the structure using the name or other unique field, than
    tell the program to delete that record EXAMPLE: car[i] ???

    2) or would this type of problem be better suited if a class was used instead of a structure? If so how?

    Thanks for any help / comments. I am new to C++ so if you chose to get fancy and impress me please explain what you are doing and how it works.

    I know thats asking for a lot, but many thanks in advance,

    Alan

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Good to see a fellow Texan! Anyway, you should probably either
    1) create your structures within a local scope and instead of worrying about it, let the variables destroy themselves as they leave that scope. You can accomplish this by simply putting a pair of { } around the routine in question. Otherwise, except that you can resize arrays with some compilers, deleting an element in the middle of an array is iffy, since you might access the deleted element by accident and so this is not recommended. Thus, a linked list is better and more stable for the job, albeit more difficult to work with. As important as the linked list is, I would recommend that you master them now, though.

    There is no real benefit to using a class as opposed to a normal structure for this. Actually, in C++, the only difference between a 'class' and a 'struct' is that by default, all 'class' data members are private, and vise versa for structs(public by default).
    That's the ONLY difference!

    Good luck!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 11:42 AM
  2. binary tree token problem
    By OldSchool in forum C++ Programming
    Replies: 13
    Last Post: 05-28-2006, 10:42 PM
  3. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  4. Data init inside of template class function
    By VirtualAce in forum C++ Programming
    Replies: 1
    Last Post: 04-24-2002, 03:11 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM

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