member variable ptr cast

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noah Roberts

    member variable ptr cast

    Consider the following hierarchy:

    struct record
    {
    };

    struct test_record
    {
    };

    struct an_object
    {
    test_record r;
    };

    I want a member pointer variable to r but I want it to be cast as a
    record. Is this possible? I tried the following:

    static_cast<rec ord an_object::*>(& an_object::r);

    No worky.
  • Victor Bazarov

    #2
    Re: member variable ptr cast

    Noah Roberts wrote:
    Consider the following hierarchy:
    >
    struct record
    {
    };
    >
    struct test_record
    {
    };
    >
    struct an_object
    {
    test_record r;
    };
    >
    I want a member pointer variable to r but I want it to be cast as a
    record. Is this possible? I tried the following:
    >
    static_cast<rec ord an_object::*>(& an_object::r);
    >
    No worky.
    'an_object' does not have a member of type 'record'.

    Now, answer my question: What do you think you need that for?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    • Noah Roberts

      #3
      Re: member variable ptr cast

      Victor Bazarov wrote:
      Noah Roberts wrote:
      >Consider the following hierarchy:
      >>
      >struct record
      >{
      >};
      >>
      >struct test_record
      >{
      >};
      >>
      >struct an_object
      >{
      > test_record r;
      >};
      >>
      >I want a member pointer variable to r but I want it to be cast as a
      >record. Is this possible? I tried the following:
      >>
      >static_cast<re cord an_object::*>(& an_object::r);
      >>
      >No worky.
      >
      'an_object' does not have a member of type 'record'.
      >
      Now, answer my question: What do you think you need that for?
      >
      test_record was supposed to be a sub of record. My mistake.

      Comment

      • Noah Roberts

        #4
        Re: member variable ptr cast (edited)

        Consider the following hierarchy:

        struct record
        {
        };

        struct test_record : record
        {
        };

        struct an_object
        {
        test_record r;
        };

        I want a member pointer variable to r but I want it to be cast as a
        record. Is this possible? I tried the following:

        static_cast<rec ord an_object::*>(& an_object::r);

        No worky.

        Comment

        • Victor Bazarov

          #5
          Re: member variable ptr cast (edited)

          Noah Roberts wrote:
          Consider the following hierarchy:
          >
          struct record
          {
          };
          >
          struct test_record : record
          {
          };
          >
          struct an_object
          {
          test_record r;
          };
          >
          I want a member pointer variable to r but I want it to be cast as a
          record. Is this possible? I tried the following:
          >
          static_cast<rec ord an_object::*>(& an_object::r);
          >
          No worky.
          I still think it's not possible. An instance of type 'an_object' does
          not *directly* contain a member of type 'record'. The fact that
          'test_record' contains a subobject of type 'record' does not matter.
          It's about the same as

          struct A { int a; };

          struct hasA { A myA; };

          int hasA::*p = hasA::myA::a; // or some such syntax.

          The use for member pointers is limited and the capabilities are limited
          because the language designers weren't concerned with any possible use
          of those.

          You still haven't answered my question: why do you think you need that?

          V
          --
          Please remove capital 'A's when replying by e-mail
          I do not respond to top-posted replies, please don't ask

          Comment

          • Noah Roberts

            #6
            Re: member variable ptr cast (edited)

            Victor Bazarov wrote:
            >
            I still think it's not possible.
            Well, I can't think of a way either.
            >
            You still haven't answered my question: why do you think you need that?
            You're being kinda demanding, don't you think? Not exactly necessary
            information to answer the question asked. I think I need it because
            I've yet to come up with an alternative solution to the problem I'm
            facing of course.

            Comment

            • Victor Bazarov

              #7
              Re: member variable ptr cast (edited)

              Noah Roberts wrote:
              Victor Bazarov wrote:
              >>
              >I still think it's not possible.
              >
              Well, I can't think of a way either.
              >
              >>
              >You still haven't answered my question: why do you think you need that?
              >
              You're being kinda demanding, don't you think? Not exactly necessary
              information to answer the question asked. I think I need it because
              I've yet to come up with an alternative solution to the problem I'm
              facing of course.
              Hell, if you don't need help, maybe you should just go solve your
              problems by yourself, don't you think? I asked because I think that
              while you're explaining you might have a revelation or somethin' or
              maybe somebody here will give you an alternative to your alternative. A
              pointer to member is a rarely needed thing. Have you tried a regular
              pointer instead?

              V
              --
              Please remove capital 'A's when replying by e-mail
              I do not respond to top-posted replies, please don't ask

              Comment

              • Noah Roberts

                #8
                Re: member variable ptr cast (edited)

                Victor Bazarov wrote:
                Noah Roberts wrote:
                >Victor Bazarov wrote:
                >>>
                >>I still think it's not possible.
                >>
                >Well, I can't think of a way either.
                >>
                >>>
                >>You still haven't answered my question: why do you think you need that?
                >>
                >You're being kinda demanding, don't you think? Not exactly necessary
                >information to answer the question asked. I think I need it because
                >I've yet to come up with an alternative solution to the problem I'm
                >facing of course.
                >
                Hell, if you don't need help, maybe you should just go solve your
                problems by yourself, don't you think?
                I asked a pretty direct question about what I needed to know. You did
                the best you could with that question. Thank you. That's all I want to
                know...don't need help doing my job.

                I asked because I think that
                while you're explaining you might have a revelation or somethin' or
                maybe somebody here will give you an alternative to your alternative. A
                pointer to member is a rarely needed thing. Have you tried a regular
                pointer instead?
                Obviously there are some pretty important differences between member
                pointer and pointer such that they are not at all interchangeable concepts.

                Comment

                Working...