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. What is the difference between c++ structs and c# structs..?

What is the difference between c++ structs and c# structs..?

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++
6 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.
  • A Offline
    A Offline
    Aslesh
    wrote on last edited by
    #1

    can any tell me what is the difference between c# and c++ structs.. Santhapur

    N M C 3 Replies Last reply
    0
    • A Aslesh

      can any tell me what is the difference between c# and c++ structs.. Santhapur

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      I have only a small idea about .net and what I understand is.. In both c++ and c#, strctures and class are used for grouping memeber variables. How ever when you create a object of strcture in c#, it is created in stack and when you create a class object, it is created in heap. In c++, the structre or class dosent have much dIfference. But if you create it uisng the new, it is created in heap and simply declaring it creates the objects in the stack. Please correct me if am wrong....

      nave [OpenedFileFinder] [My Blog]

      1 Reply Last reply
      0
      • A Aslesh

        can any tell me what is the difference between c# and c++ structs.. Santhapur

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Structs are used in both languages to encapsulate related variables. Structs differ between C++ and C# in how they compare with classes. In C#, a struct is a value type, while a class is a reference type. In the managed world, there are value types, which can be and most often are stored on the stack (or as a member of a class) and reference types which are always allocated on a heap. In C#, a struct is a value type, while a class is a reference type. This is an important concept in C# - for example, when you pass a struct as a function parameter, it is passed by value, so if the function changes the struct, the original passed object is untouched. When a class object is passed it is by reference, so any changes made by the function change the original object. That difference is why C# doesn't need *, &, and -> operators all over the place. In the native C++ world, structs and classes are the same except for default member access. Both can be allocated on the stack or the heap. Reference and value are controlled by operators, like *, &, ., and -> Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • A Aslesh

          can any tell me what is the difference between c# and c++ structs.. Santhapur

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          And what is the difference between a C# class and a C++ one? And what about the new keyword? Hey, is there also any difference on the inheritance paradigm? ... :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          I 1 Reply Last reply
          0
          • C CPallini

            And what is the difference between a C# class and a C++ one? And what about the new keyword? Hey, is there also any difference on the inheritance paradigm? ... :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            Getting soft... I was expecting:

            CPallini shoulda wrote:

            About 3 characters.

            C 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              Getting soft... I was expecting:

              CPallini shoulda wrote:

              About 3 characters.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              :-D :laugh: :-D You're great. Anyway, that's right: I feel a bit weak this morning. :) BTW welcome in the THHB. (Official investiture on my blog [^].)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              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