CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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
  •  





Click Here to Expand Forum to Full Width

Featured