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. Difference between "C structure" and "C++ structure".

Difference between "C structure" and "C++ structure".

Scheduled Pinned Locked Moved C / C++ / MFC
c++
13 Posts 7 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.
  • S Scorpio

    Please tell me Difference between "C structure" and "C++ structure".

    _ Offline
    _ Offline
    _AnsHUMAN_
    wrote on last edited by
    #2

    The variables in C structure are by default public but in C++ they are private Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

    S T K 3 Replies Last reply
    0
    • S Scorpio

      Please tell me Difference between "C structure" and "C++ structure".

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #3

      See Here[^]_**


      **_

      whitesky


      1 Reply Last reply
      0
      • _ _AnsHUMAN_

        The variables in C structure are by default public but in C++ they are private Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

        S Offline
        S Offline
        Scorpio
        wrote on last edited by
        #4

        is it true that constructor will be called for class but there will be no constructor for the structure

        _ T 2 Replies Last reply
        0
        • S Scorpio

          is it true that constructor will be called for class but there will be no constructor for the structure

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #5

          Structures don't have constructors and how can they be called if they don't exist. Yes but still what you say is correct. It would be better to initialize the member's of the structure somewhere(more preferrably the constructor of the class) before using them. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

          L T 2 Replies Last reply
          0
          • _ _AnsHUMAN_

            Structures don't have constructors and how can they be called if they don't exist. Yes but still what you say is correct. It would be better to initialize the member's of the structure somewhere(more preferrably the constructor of the class) before using them. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

            L Offline
            L Offline
            Laxman Auti
            wrote on last edited by
            #6

            We may have a Constructer's for C++ Structures(look the Following code) C++ Structure's can be initialized/copied by overloading the Assignment Operator Like following

            struct Mypoint
            {
            int x,y;
            Mypoint() : x(0),y(0){};
            const Mypoint &operator = (const Mypoint &me)
            {
            x=me.x;
            y=me.y;
            return *this;
            };

            Knock out 'T' from CAN'T , You 'CAN' if you think you 'CAN' :cool:

            1 Reply Last reply
            0
            • _ _AnsHUMAN_

              The variables in C structure are by default public but in C++ they are private Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #7

              _AnShUmAn_ wrote:

              The variables in C structure are by default public but in C++ they are private

              have you tried that?

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              _ 1 Reply Last reply
              0
              • S Scorpio

                is it true that constructor will be called for class but there will be no constructor for the structure

                T Offline
                T Offline
                ThatsAlok
                wrote on last edited by
                #8

                NiLeSh KoRpE wrote:

                there will be no constructor for the structure

                Have a try!

                #include
                #include struct ab
                {
                ab()
                {
                printf("alok");
                }
                };
                main()
                {
                ab a;
                int *hello;
                printf("Hi, Enter any value > ");
                hello=(int*)malloc(sizeof(int));
                scanf("%d",hello);
                }

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                cheers, Alok Gupta VC Forum Q&A :- I/ IV

                1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  Structures don't have constructors and how can they be called if they don't exist. Yes but still what you say is correct. It would be better to initialize the member's of the structure somewhere(more preferrably the constructor of the class) before using them. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #9

                  _AnShUmAn_ wrote:

                  It would be better to initialize the member's of the structure

                  you can create Construtor in Structure, see the example i have quoted in post above you!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  cheers, Alok Gupta VC Forum Q&A :- I/ IV

                  1 Reply Last reply
                  0
                  • T ThatsAlok

                    _AnShUmAn_ wrote:

                    The variables in C structure are by default public but in C++ they are private

                    have you tried that?

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta VC Forum Q&A :- I/ IV

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #10

                    Ok, I tried your code. Its working fine. Thanks for the update and clarification. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                    T 1 Reply Last reply
                    0
                    • _ _AnsHUMAN_

                      Ok, I tried your code. Its working fine. Thanks for the update and clarification. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                      T Offline
                      T Offline
                      ThatsAlok
                      wrote on last edited by
                      #11

                      _AnShUmAn_ wrote:

                      Thanks for the update and clarification.

                      It's OK,I learn a lot while dicussing with you! :)

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta VC Forum Q&A :- I/ IV

                      1 Reply Last reply
                      0
                      • S Scorpio

                        Please tell me Difference between "C structure" and "C++ structure".

                        N Offline
                        N Offline
                        NiceNaidu fo
                        wrote on last edited by
                        #12

                        C allows struct, union, and enum types to be declared within function prototype scope, e.g.: extern void foo(const struct info { int typ; int sz; } *s); int bar(struct point { int x, y; } pt) { ... } C also allows structure types to be declared as function return types, as in: extern struct pt { int x; } pos(void); C++ does not allow either of these, since the scope of the structure declared in this fashion does not extend outside the function declaration or definition, making it impossible to define objects of that structure type which could be passed as arguments to the function or to assign function return values into objects of that type. Appu.. "If you judge people, you have no time to love them."

                        1 Reply Last reply
                        0
                        • _ _AnsHUMAN_

                          The variables in C structure are by default public but in C++ they are private Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                          K Offline
                          K Offline
                          knoxplusplus
                          wrote on last edited by
                          #13

                          Hi !!! YOu haven't right.:zzz: By !!! -:KNOX:-

                          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