Thread: structures or not?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    structures or not?

    I need to store the info for all the items and weapons. Such as the the profiencies of the weapon and what to display in the inventory. I was just wondering if structures is the right way to go.
    My computer is awesome.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Yes... Using structures would be a correct implementation (from a design standpoint). Since you have groups of data which are logically connected, you can make the connection explicit by using a structure to encapsulate the data.

    That said, there are many ways to implement what you want to do using structures, some are better than otehrs, but a lot depends on the design of the rest of your program, and how "fancy" you want to get with your structures.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    But since this is C++, you should be using classes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    3
    Quote Originally Posted by Salem
    But since this is C++, you should be using classes.
    I don't agree with you totally there. You have to look from a designer's point of view. Yes, you could use classes to store just data but that's kind of strange. Grouping data does not fit into object oriented programming. I consider groupings of data as records and not objects. Also you would have to give the data members in a class public access. More work! And one might forget to do so. Structures are the way to go if you are working with records or blocks of data. I don't think C++ intended the programmer to use classes for reading blocks of data.

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Quote Originally Posted by fsp
    I don't think C++ intended the programmer to use classes for reading blocks of data.
    You haven't looked into I/O streams much, have you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM