empty structs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cath8024
    New Member
    • Apr 2007
    • 7

    empty structs

    can somebody give me a use for a struct with no member variables.
  • reon
    New Member
    • Feb 2007
    • 80

    #2
    please make the question clear....

    struct is equal to class keyword in C++.

    the difference is class is holding private as default access specifier and struct is having public..
    And there is no need to mention access specifiers inside struct....defau lt is public...

    Comment

    • cath8024
      New Member
      • Apr 2007
      • 7

      #3
      Consider a struct as below.
      struct Test1 {};
      I got from the net that C++ allows empty struct or class (gcc 4.0 supports empty struct even in C). Empty struct/class can be used as a placeholder for future development.
      Can somebody illustrate how an empty struct can be used as a placeholder.

      Comment

      • cath8024
        New Member
        • Apr 2007
        • 7

        #4
        why use empty structs

        An empty struct has no member variables.
        Then for what purpose do we use them?
        please help me.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          If you add an empty struct as the first member of another struct, the empty
          struct can serve as a "marker interface", i.e. when you cast a pointer to that
          outer struct to a pointer of the inner struct and the cast succeeds you know
          that the outer struct is "marked" as something. This just works when you use
          C++ though; for C there is little use for an empty struct.

          kind regards,

          Jos

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            cath8024

            Please do not double post on the same subject.
            Please do read our posting guidelines.

            Banfa
            Administrator

            Comment

            Working...