• <i id='FWLfd'><tr id='FWLfd'><dt id='FWLfd'><q id='FWLfd'><span id='FWLfd'><b id='FWLfd'><form id='FWLfd'><ins id='FWLfd'></ins><ul id='FWLfd'></ul><sub id='FWLfd'></sub></form><legend id='FWLfd'></legend><bdo id='FWLfd'><pre id='FWLfd'><center id='FWLfd'></center></pre></bdo></b><th id='FWLfd'></th></span></q></dt></tr></i><div id='FWLfd'><tfoot id='FWLfd'></tfoot><dl id='FWLfd'><fieldset id='FWLfd'></fieldset></dl></div>

    <small id='FWLfd'></small><noframes id='FWLfd'>

  • <tfoot id='FWLfd'></tfoot>

    <legend id='FWLfd'><style id='FWLfd'><dir id='FWLfd'><q id='FWLfd'></q></dir></style></legend>

          <bdo id='FWLfd'></bdo><ul id='FWLfd'></ul>


        What does `*amp;` in a function declaration mean?(函数声明中的“*amp;是什么意思?)
            <tfoot id='zkxpK'></tfoot>
              <bdo id='zkxpK'></bdo><ul id='zkxpK'></ul>
                <tbody id='zkxpK'></tbody>
                <i id='zkxpK'><tr id='zkxpK'><dt id='zkxpK'><q id='zkxpK'><span id='zkxpK'><b id='zkxpK'><form id='zkxpK'><ins id='zkxpK'></ins><ul id='zkxpK'></ul><sub id='zkxpK'></sub></form><legend id='zkxpK'></legend><bdo id='zkxpK'><pre id='zkxpK'><center id='zkxpK'></center></pre></bdo></b><th id='zkxpK'></th></span></q></dt></tr></i><div id='zkxpK'><tfoot id='zkxpK'></tfoot><dl id='zkxpK'><fieldset id='zkxpK'></fieldset></dl></div>

                  <small id='zkxpK'></small><noframes id='zkxpK'>

                • <legend id='zkxpK'><style id='zkxpK'><dir id='zkxpK'><q id='zkxpK'></q></dir></style></legend>




                  void myFunc(myStruct *&out) {out = 新的 myStruct;out->field1 = 1;out->field2 = 2;}


                  myStruct *data;myFunc(数据);

                  这将填充data中的所有字段.如果我在声明中省略了 '&',这将不起作用.(或者更确切地说,它只会在函数中本地工作,但不会改变调用者的任何内容)



                  The &C++ 变量声明中的符号表示它是一个引用.>


                  所以,重申一下,这里的操作符号"不是 *&,这种组合本身并不意味着很多.*myStruct * 类型的一部分,即指向 myStruct 的指针",而 & 使得它是一个引用,因此您可以将其读作out 是对指向 myStruct 的指针的引用".


                  void myFunc(myStruct * &out)


                  void myFunc(myStruct* &out)


                  I wrote a function along the lines of this:

                  void myFunc(myStruct *&out) {
                      out = new myStruct;
                      out->field1 = 1;
                      out->field2 = 2;

                  Now in a calling function, I might write something like this:

                  myStruct *data;

                  which will fill all the fields in data. If I omit the '&' in the declaration, this will not work. (Or rather, it will work only locally in the function but won't change anything in the caller)

                  Could someone explain to me what this '*&' actually does? It looks weird and I just can't make much sense of it.


                  The & symbol in a C++ variable declaration means it's a reference.

                  It happens to be a reference to a pointer, which explains the semantics you're seeing; the called function can change the pointer in the calling context, since it has a reference to it.

                  So, to reiterate, the "operative symbol" here is not *&, that combination in itself doesn't mean a whole lot. The * is part of the type myStruct *, i.e. "pointer to myStruct", and the & makes it a reference, so you'd read it as "out is a reference to a pointer to myStruct".

                  The original programmer could have helped, in my opinion, by writing it as:

                  void myFunc(myStruct * &out)

                  or even (not my personal style, but of course still valid):

                  void myFunc(myStruct* &out)

                  Of course, there are many other opinions about style. :)




                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)
                    <tbody id='vFW40'></tbody>

                    <legend id='vFW40'><style id='vFW40'><dir id='vFW40'><q id='vFW40'></q></dir></style></legend>
                  • <tfoot id='vFW40'></tfoot>
                      <bdo id='vFW40'></bdo><ul id='vFW40'></ul>

                          <i id='vFW40'><tr id='vFW40'><dt id='vFW40'><q id='vFW40'><span id='vFW40'><b id='vFW40'><form id='vFW40'><ins id='vFW40'></ins><ul id='vFW40'></ul><sub id='vFW40'></sub></form><legend id='vFW40'></legend><bdo id='vFW40'><pre id='vFW40'><center id='vFW40'></center></pre></bdo></b><th id='vFW40'></th></span></q></dt></tr></i><div id='vFW40'><tfoot id='vFW40'></tfoot><dl id='vFW40'><fieldset id='vFW40'></fieldset></dl></div>

                            <small id='vFW40'></small><noframes id='vFW40'>