Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Ask for help: C++ struct

Ask for help: C++ struct

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chenxiujie
    wrote on last edited by
    #1

    Hello, everyone, Who know the different between C Struct and C++ Struct? Please tell me?

    J F T B 4 Replies Last reply
    0
    • C chenxiujie

      Hello, everyone, Who know the different between C Struct and C++ Struct? Please tell me?

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      In C a structure is a colection of data items only. In C++ a structure is the same as a class, accept that the default access is public instead of private. INTP Every thing is relative...

      F 1 Reply Last reply
      0
      • C chenxiujie

        Hello, everyone, Who know the different between C Struct and C++ Struct? Please tell me?

        F Offline
        F Offline
        Fired Fish
        wrote on last edited by
        #3

        guy .From your name I know you come from cn 两种结构体式一样的把 ---------------------------- Jerry yu Chinese programming fans

        1 Reply Last reply
        0
        • J John R Shaw

          In C a structure is a colection of data items only. In C++ a structure is the same as a class, accept that the default access is public instead of private. INTP Every thing is relative...

          F Offline
          F Offline
          Fired Fish
          wrote on last edited by
          #4

          DEAR SIR can you give a example I donot understand your say ---------------------------- Jerry yu Chinese programming fans 我的QQ 290785513 中国人的加我

          T 1 Reply Last reply
          0
          • C chenxiujie

            Hello, everyone, Who know the different between C Struct and C++ Struct? Please tell me?

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            in addition to what John said, a C++ structure can accept the following by opposition to C structs : - visibility operators (public, protected, private) - member functions - inherit from another type a C structure is so only an aggregation of several types, all public. a C++ struct do is a class, but which members are public by default... if you don't understand more, search for a C++ book and learn about the language.


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            1 Reply Last reply
            0
            • F Fired Fish

              DEAR SIR can you give a example I donot understand your say ---------------------------- Jerry yu Chinese programming fans 我的QQ 290785513 中国人的加我

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              in C++ :

              //C++ struct definition...
              struct MyStruct {
              int i;
              double d;
              };

              will actually be seen by the compiler as the following code :

              class MyStruct {
              public:
              int i;
              double d;

              public:
              MyStruct() { }
              virtual ~MyStruct() { }
              };

              see if you can find any differences...


              in the same way, the following code wont compile with a pure C compiler :

              struct Formula1 : public SportCar { //inheritence not allowed
              private: //visibility change not allowed
              Motor m;
              double max_speed;

              public:
              double getMaxSpeed(); //member functions not allowed
              };


              TOXCCT >>> GEII power
              [toxcct][VisualCalc] -- modified at 7:05 Saturday 19th November, 2005

              1 Reply Last reply
              0
              • C chenxiujie

                Hello, everyone, Who know the different between C Struct and C++ Struct? Please tell me?

                B Offline
                B Offline
                Bob Stanneveld
                wrote on last edited by
                #7

                Hello, A struct in C++ is the same as C. It's only there for compatibility with C. There is no real difference. When you use C++, you can add member functions and all the other stuff that you can use with a class. I can only advice not too do it. The main reason for this is that everybody uses a struct as a POD (Plain Old Datatype) and a class for dynamic objects. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                C 1 Reply Last reply
                0
                • B Bob Stanneveld

                  Hello, A struct in C++ is the same as C. It's only there for compatibility with C. There is no real difference. When you use C++, you can add member functions and all the other stuff that you can use with a class. I can only advice not too do it. The main reason for this is that everybody uses a struct as a POD (Plain Old Datatype) and a class for dynamic objects. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                  C Offline
                  C Offline
                  chenxiujie
                  wrote on last edited by
                  #8

                  Thank you very much. I find the real reason from your answer. Yesterday, I read a block source code of C++. In it, I found some structs are defined as C style, I feel very strange, So I ask this question. Now I understood it only want to treat the struct as a Datatype.

                  B 1 Reply Last reply
                  0
                  • C chenxiujie

                    Thank you very much. I find the real reason from your answer. Yesterday, I read a block source code of C++. In it, I found some structs are defined as C style, I feel very strange, So I ask this question. Now I understood it only want to treat the struct as a Datatype.

                    B Offline
                    B Offline
                    Bob Stanneveld
                    wrote on last edited by
                    #9

                    chenxiujie wrote:

                    Thank you very much.

                    You're welcome! :-D Glad that you found my help usefull. :) Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups