C++ Classes: Which are the differences between 'struct' and 'class'?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: C++ Classes: Which are the differences between 'struct' and 'class'?

Hybrid View

  1. #1
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    C++ Classes: Which are the differences between 'struct' and 'class'?

    Q: Which are the differences between struct and class?

    A: In C++ programming language, there is no difference between classes defined by using struct or class keywords, except the default access to members and base classes.

    • for struct the default access is public;
    • for class the default access is private.

    Examples
    1. Code:
      struct SFoo : Base
      {
         int m_foo;
         void Foo();
      };
      is equivalent to
      Code:
      struct SFoo : public Base
      {
      public:
         int m_foo;
         void Foo();
      };
    2. Code:
      class CFoo : Base
      {
         int m_foo;
         void Foo();
      };
      is equivalent to
      Code:
      class CFoo : private Base
      {
      private:
         int m_foo;
         void Foo();
      };


    See also
    Last edited by ovidiucucu; May 3rd, 2011 at 02:01 AM.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center