meaning of *& syntax

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

    #1

    meaning of *& syntax

    Hi there,

    I just came across the following syntax in a class declaration:

    my_base*& base_;

    What does that mean? Is it a pointer to a reference? In my head * and & are
    opposites meaning that my_base*& == my_base ...
    But I have a feeling that I'm wrong ... :o)

    Best Regards
    Hansen


  • Clark S. Cox III

    #2
    Re: meaning of *& syntax

    Hansen wrote:
    Hi there,
    >
    I just came across the following syntax in a class declaration:
    >
    my_base*& base_;
    >
    What does that mean? Is it a pointer to a reference?
    Close, it's a reference to a pointer.
    In my head * and & are
    opposites meaning that my_base*& == my_base ...
    But I have a feeling that I'm wrong ... :o)
    Just like (int&) is a reference to an int, (int*&) is a reference to an
    int pointer.


    --
    Clark S. Cox III
    clarkcox3@gmail .com

    Comment

    • Rolf Magnus

      #3
      Re: meaning of *& syntax

      Hansen wrote:
      Hi there,
      >
      I just came across the following syntax in a class declaration:
      >
      my_base*& base_;
      >
      What does that mean? Is it a pointer to a reference?
      No. There are no such things as pointers to references. It's just the other
      way round. It's a reference to a pointer.
      In my head * and & are opposites meaning that my_base*& == my_base ...
      my_base*& is a type. What you mean would be *&my_base.

      Comment

      • Grizlyk

        #4
        Re: meaning of *& syntax


        Hansen wrote:
        >
        I just came across the following syntax in a class declaration:
        >
        my_base*& base_;
        >
        What does that mean?
        "cdecl/cppdecl" can help you sometimes to resolve c-language expressions.

        Also find a table with "C++ precedens of operators": all operators have
        divided on groups by "priority level" and "associativ ity" ("left to right"
        or "right to left").


        --
        Maksim A. Polyanin

        "In thi world of fairy tales rolls are liked olso"
        /Gnume/



        Comment

        • Clark S. Cox III

          #5
          Re: meaning of *& syntax

          Grizlyk wrote:
          Hansen wrote:
          >I just came across the following syntax in a class declaration:
          >>
          >my_base*& base_;
          >>
          >What does that mean?
          >
          "cdecl/cppdecl" can help you sometimes to resolve c-language expressions.
          >
          Also find a table with "C++ precedens of operators": all operators have
          divided on groups by "priority level" and "associativ ity" ("left to right"
          or "right to left").
          This is not entirely true, some of the relationships between the
          operators cannot be expressed in a simple precedence table.

          --
          Clark S. Cox III
          clarkcox3@gmail .com

          Comment

          • Grizlyk

            #6
            Re: meaning of *& syntax

            Clark S. Cox III wrote:
            >>
            >Also find a table with "C++ precedens of operators": all operators have
            >divided on groups by "priority level" and "associativ ity" ("left to
            >right"
            >or "right to left").
            >
            This is not entirely true, some of the relationships between the
            operators cannot be expressed in a simple precedence table.
            For example?

            --
            Maksim A. Polyanin

            "In thi world of fairy tales rolls are liked olso"
            /Gnume/


            Comment

            • =?ISO-8859-15?Q?Juli=E1n?= Albo

              #7
              Re: meaning of *& syntax

              Grizlyk wrote:
              >This is not entirely true, some of the relationships between the
              >operators cannot be expressed in a simple precedence table.
              For example?
              Yes.

              --
              Salu2

              Comment

              • Clark S. Cox III

                #8
                Re: meaning of *& syntax

                Grizlyk wrote:
                Clark S. Cox III wrote:
                >>Also find a table with "C++ precedens of operators": all operators have
                >>divided on groups by "priority level" and "associativ ity" ("left to
                >>right"
                >>or "right to left").
                >This is not entirely true, some of the relationships between the
                >operators cannot be expressed in a simple precedence table.
                >
                For example?
                >
                Consider the relationship between the '=' operator and the '?:' operator:

                a?b:c=3; //Equivalent to a?b:(c=3)
                a?b=3:c; //Equivalent to a?(b=3):c
                a=3?b:c; //Equivalent to a=(3?b:c)


                --
                Clark S. Cox III
                clarkcox3@gmail .com

                Comment

                • Craig Scott

                  #9
                  Re: meaning of *& syntax

                  I just came across the following syntax in a class declaration:
                  >
                  my_base*& base_;
                  >
                  What does that mean? Is it a pointer to a reference?
                  >
                  Close, it's a reference to a pointer.
                  >
                  In my head * and & are
                  opposites meaning that my_base*& == my_base ...
                  But I have a feeling that I'm wrong ... :o)
                  >
                  Just like (int&) is a reference to an int, (int*&) is a reference to an
                  int pointer.
                  Since the OP hasn't seen this before, I mention the following as
                  additional info. It can be useful to pass a "reference to a pointer"
                  to functions that need to change what the pointer points to from the
                  *caller's* point of view. For example (this is a very contrived
                  example):

                  void func(int*& foo, int* t)
                  {
                  // A real function would obviously do something
                  // more meaningful here!
                  foo = t;
                  }

                  int main(int argc, char* argv[])
                  {
                  int a = 0;
                  int b = 1;
                  int* myFoo = &a;

                  // This prints the value of a, which is 0
                  std::cout << *myFoo << std::endl;

                  // This will change myFoo to point to b
                  func(myFoo, &b);

                  // This now prints the value of b, which is 1
                  std::cout << *myFoo << std::endl;
                  }


                  Member variables can also be used in a similar fashion, but in my
                  experience, that is less common (but not any more or less valid).

                  --
                  Computational Fluid Dynamics, CSIRO (CMIS)
                  Melbourne, Australia

                  Comment

                  Working...