Thread: Classes or Structs?

  1. #1
    Registered User DeanDemon's Avatar
    Join Date
    Nov 2002
    Posts
    37

    Question Classes or Structs?

    Which one do you prefer?

    And what type of loop do you most often use?

    My answers: Classes, For.
    -Dean

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Are you talking about C++ structs or C structs? Since this is posted on the C++ Board I'll assume C++ structs. There aren't really any differences except in structs everything is treated as public. So, I guess my answer is I use classes more.

    I probably use the while loop the most.

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Structs are easier, but classes are far more useful.

    As for loops, I'd have to say that I use while loops the most, although I like do loops more than most other programmers I talk to. I think they're great for error traps and repeating a program.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    i really haven't worked much with structs or classes, more with classes though. i like classes better, seem to be more useful. in regards to loops: i like for loops better; in regards to which one i use more, i don't know, depends what i want done, usually while or for.

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    in C++ structs and classes are pretty much exactly the same (same in functionality, but different in that structs default to public while classes default to private).

    I usually use for loops most

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Seems like a stupid question but....

    classes
    while loop
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User adamviper's Avatar
    Join Date
    Nov 2002
    Posts
    132
    struct & switch

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by adamviper
    struct & switch
    Didn't know switch was an iterator .

    I prefer none, I use classes in certan circumstances (sp?) and structs in others.
    I believe I use while the most.

    PS: In this for loop, which value does i have after the iteration ends? 4 or 5?
    i = 4 is the last valid value, but i = 5 is what makes i<5 false.

    int i;
    for(i=0; i<5; i++)
    {
    ...
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I don't know why do you keep asking about which loops are better?
    There is no best loop, each loop is deferent from the others, and you use each one according to what you need.
    none...

  10. #10
    end0
    Guest
    classes and for loops

    for loops are far more useful because of their versatility, but thats the only reason I use them more.

  11. #11
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Magos
    PS: In this for loop, which value does i have after the iteration ends? 4 or 5?
    i = 4 is the last valid value, but i = 5 is what makes i<5 false.
    Code:
    int i;
    for(i=0; i<5; i++)
    {
       ...
    }
    Because for is a pretest loop, the last value i has is 4.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  12. #12
    No Man..
    Guest

    ...

    as you start doing more and more programming you end up using..

    while loops and classes..

    for loops require that you know things in advance.


    ..the beauty of a binary tree is that there is no need for a loop.. since every node is a mini tree.. you can just hop a long with recursion.


    ...and i = 5 when that loop ends. i = 4 will be the last value WITHIN the loop

    but if you did

    for (i = 0; i < 5; i++)
    {
    ....
    }

    cout << i;

    the console would display..

    5

  13. #13
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: ...

    Originally posted by No Man..
    for loops require that you know things in advance.
    You don't need to know any more data for a for loop than you would for a while loop. It's purely a matter of preferance just like struct vs. class. Structs and classes pretty much are the same cept for default access to members.
    Last edited by Polymorphic OOP; 12-05-2002 at 04:42 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structs or classes?
    By legit in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2009, 10:16 AM
  2. classes, structs and unions
    By Luciferek in forum C++ Programming
    Replies: 24
    Last Post: 08-09-2008, 10:26 AM
  3. Why use Classes instead of Structs?
    By yaya in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2008, 12:39 AM
  4. Are structs and classes the same thing?
    By dwks in forum C++ Programming
    Replies: 6
    Last Post: 11-25-2005, 03:21 PM
  5. Classes or Structs faster for Lists
    By White Rider in forum C++ Programming
    Replies: 24
    Last Post: 04-05-2002, 03:57 PM