简体   繁体   中英

Argument passed by value appears as passed by reference in the debugger in Visual Studio 2010, C++

I'm currently debugging a project I've been working on for a while, and, as I wanted to know the content of a QString named file, and thus wrote file.d in my watched variables, I just noticed that file was actually an address.

The thing is, file was not an address in my code.

Here is the function I was in :

void MyClass::updateFile(QString file, QTreeWidgetItem *item)
{
   if(file.isEmpty())
      return;
    QFile f(file); // Line were I had the breakpoint
...
}

So I checked the stack and it was really written

updateFile(QString *file, QTreeWidgetItem *item)

I first thought of a compiler optimization, but since I was in debug mode, that seems unlikely.

Do you have an explanation ?

EDIT : I must add that when I changed the signature to

void MyClass::updateFile(QString const &file, QTreeWidgetItem *item)

The problem disappears and debugger and code have the same signature again.

Passing by value/reference is a C++ aspect. At the assembly level, a big structure might still be copied somewhere and passed by pointer. Its the C++ semantics that you are working on a duplicate, but assembly cannot pass by value all sorts of structs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM