简体   繁体   English

方法签名C ++

[英]Method signature C++

Having trouble understanding method signature in C++. 无法理解C ++中的方法签名。 Looking for a second opinion. 寻找第二意见。

readPage(File* file, const PageId pageNo, Page*& page) {}

The above can be re-written as follows? 上面可以重写如下吗?

readPage(File *file, const PageId pageNo, Page *&page) {}

So, *file is pointer that is being passed in and *&page is something's address that is then converted to a pointer? 那么,* file是要传入的指针,而*&page是要转换为指针的东西的地址吗? I'm confused with the combination of *& 我对*&的组合感到困惑

file is a pointer to a File , which means that any changes to what it points to, like file是指向File的指针,这意味着对其指向的内容进行任何更改,例如

file->doSomething(); // the caller will see this change

will be seen by the calling side, but if one overwrites the pointer, that not only the new value of the pointer not going to be seen by the caller, but any changes to the file after that will also not be observed, because it's a pointer to a different File now, and because the pointer itself is passed by value. 会在调用方看到,但是如果覆盖指针,不仅调用者不会看到指针的新值,而且此后对文件的任何更改也不会被观察到,因为它是一个现在指向另一个File的指针,因为指针本身是通过值传递的。

file = new File(); // the caller will not see this change
file->doSomething(); // neither will it see this one

Now, page is a reference to a pointer to a Page . 现在, page是对指向Page的指针的引用。 In other words, it behaves like a pointer, so 换句话说,它的行为就像一个指针,因此

page->doSomething(); // the caller will see this change

is still observed by the caller. 仍然被呼叫者观察到。 But now if you overwrite the pointer, the caller's pointer will also be changed, and hence all consecutive changes will also be seen: 但是现在,如果您覆盖指针,则调用者的指针也将被更改,因此所有连续的更改也将被看到:

page = new Page(); // caller also sees this change
page->doSomething(); // and this too

This is because the pointer itself is passed by reference, so any changes to the pointer itself are observed by the calling side. 这是因为指针本身是通过引用传递的,因此调用者可以观察到指针本身的任何更改。

(and yes, the way you place spaces does not matter, so the two ways you provided are identical) (是的,放置空间的方式无关紧要,因此您提供的两种方式是相同的)

Page *&是指向页面的指针

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Objective-C / C ++-链接器错误/方法签名问题 - Objective-C/C++ - Linker error/Method Signature issue C ++相同的方法签名但返回类型不同 - C++ identical method signature but different return type C ++强制在子类中实现方法,但签名不同 - C++ force implementation of method in child class but with a different signature 带有和不带throw()的方法/构造函数签名中的c ++,用于自定义异常 - c++ with and without throw() in method/constructor signature for a custom exception 在C ++方法签名中,*是什么意思? - What does the * mean when in a C++ method signature? C ++ Polymorphism-调用具有不同签名的派生类方法 - C++ Polymorphism- call derived class method with different signature 多个超类中的多个 Inheritance、C++ 和相同的方法签名 - Multiple Inheritance, C++ and Same Method Signature in Multiple Super Classes C ++中无法解决的外部问题:Visual C ++操纵方法签名与dll中操纵方法不同 - Unresolved Externals in C++: Visual C++ mangles method signature differently from mangled method in dll CallStaticBooleanMethodV的返回类型与Java方法签名不匹配-从C / C ++调用Java方法 - Return type of CallStaticBooleanMethodV does not match Java method signature - Calling Java method from C/C++ C ++的新功能,签名定义 - New to C++, signature definition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM