CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 5 of 5 FirstFirst ... 2345
Results 61 to 64 of 64

Thread: Struct vs Class

  1. #61
    Join Date
    Jan 2011
    Location
    INDIA
    Posts
    2

    Resolved Re: Struct vs Class

    To maintain compatibility wid c Mr. Bajarne introduced a new keyword in c++ named c++ and while using c++ compiler u can use struct same as class

  2. #62
    Join Date
    Jan 2011
    Posts
    2

    Post Re: Struct vs Class

    Besides the visibility of members,

    Structs are value types and classes are reference types.

    As you know, value types are allocated on the stack or inline as a part of another object while classes are allocated on the heap.

    Struct is often a small object that needs to be treated like a primitive type while classes are normally used for implementation requiring more processing power. In other words, classes would normally be used to implement a piece of business logic, rather than to support data related or primitive-type objects.

    I hope this clears it up a bit.

  3. #63
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Struct vs Class

    Quote Originally Posted by amira7 View Post
    Structs are value types and classes are reference types.
    No God dammit! That is simply not true. Stop spreading around false information. As Paul already stated 5 years ago:

    Quote Originally Posted by Paul McKenzie View Post
    There is *no*, *none*, *zero* difference between a "struct" and a "class" except for the access specifiers.
    That is the only definitive answer.

    Could a moderator get this thread locked once and for all?
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #64
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Struct vs Class

    Quote Originally Posted by amira7 View Post
    Structs are value types and classes are reference types.
    Nonsense, wrong in C++. Already discussed many times in this 6 years-old thread.

    Quote Originally Posted by monarch_dodra View Post
    Could a moderator get this thread locked once and for all?
    My pleasure.

    [ Thread closed ]
    Last edited by ovidiucucu; January 10th, 2011 at 10:02 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Page 5 of 5 FirstFirst ... 2345

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured