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. Structure/Class with optional data

Structure/Class with optional data

Scheduled Pinned Locked Moved C / C++ / MFC
questionwpf
7 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.
  • 4 Offline
    4 Offline
    4288
    wrote on last edited by
    #1

    In my previous post I realized I pretty messed up my project with unneeded templates. I thought "what about creating a structure or class with a pointer to another structure and putting that pointer just when needed?" So here's the question: I dislike personally the idea of a pointer pointing to optional data, is there any better solution to store data which always has a common header but then may vary?

    ---

    C C E 4 4 Replies Last reply
    0
    • 4 4288

      In my previous post I realized I pretty messed up my project with unneeded templates. I thought "what about creating a structure or class with a pointer to another structure and putting that pointer just when needed?" So here's the question: I dislike personally the idea of a pointer pointing to optional data, is there any better solution to store data which always has a common header but then may vary?

      ---

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      create a class to store the 'common header'. then, use that as a base class and derive objects from it to store the 'optional' data. ?

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • 4 4288

        In my previous post I realized I pretty messed up my project with unneeded templates. I thought "what about creating a structure or class with a pointer to another structure and putting that pointer just when needed?" So here's the question: I dislike personally the idea of a pointer pointing to optional data, is there any better solution to store data which always has a common header but then may vary?

        ---

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

        I don't really know about your requirements, but a union may possibly be an option.

        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
        • 4 4288

          In my previous post I realized I pretty messed up my project with unneeded templates. I thought "what about creating a structure or class with a pointer to another structure and putting that pointer just when needed?" So here's the question: I dislike personally the idea of a pointer pointing to optional data, is there any better solution to store data which always has a common header but then may vary?

          ---

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          :) ? :

          class A
          {
          ...
          };

          class B
          {
          A* m_pA;
          public:
          B(A* pA = NULL) { m_pA = pA; };
          };

          int main()
          {
          A a;
          B b1; // just because it (the passing of a) is not needed
          B b2(&a); // just because it (the passing of a) is needed
          ...
          return 0;
          }

          virtual void BeHappy() = 0;

          1 Reply Last reply
          0
          • 4 4288

            In my previous post I realized I pretty messed up my project with unneeded templates. I thought "what about creating a structure or class with a pointer to another structure and putting that pointer just when needed?" So here's the question: I dislike personally the idea of a pointer pointing to optional data, is there any better solution to store data which always has a common header but then may vary?

            ---

            4 Offline
            4 Offline
            4288
            wrote on last edited by
            #5

            The hierarchy proposal is good I have to admit it. But I need to use data stored in this class in the easiest way possible, something like

            MYclass a;
            a.GetPoints();
            CalculateOtherData( a.RetrievePoints() );

            and the hierarchy isn't that simple

            ---

            D 1 Reply Last reply
            0
            • 4 4288

              The hierarchy proposal is good I have to admit it. But I need to use data stored in this class in the easiest way possible, something like

              MYclass a;
              a.GetPoints();
              CalculateOtherData( a.RetrievePoints() );

              and the hierarchy isn't that simple

              ---

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              4288 wrote:

              But I need to use data stored in this class in the easiest way possible, something like MYclass a; a.GetPoints(); CalculateOtherData( a.RetrievePoints() ); and the hierarchy isn't that simple

              So what does any of this have to do with, "...is there any better solution to store data which always has a common header but then may vary?"

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Man who follows car will be exhausted." - Confucius

              4 1 Reply Last reply
              0
              • D David Crow

                4288 wrote:

                But I need to use data stored in this class in the easiest way possible, something like MYclass a; a.GetPoints(); CalculateOtherData( a.RetrievePoints() ); and the hierarchy isn't that simple

                So what does any of this have to do with, "...is there any better solution to store data which always has a common header but then may vary?"

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Man who follows car will be exhausted." - Confucius

                4 Offline
                4 Offline
                4288
                wrote on last edited by
                #7

                That structure of points may vary.

                ---

                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