Solved "&/*parent*/" as argument?
-
I found the following sample coding from Qt documentation. Can you please explain the highlighted part? I am trying to understand the syntax for the argument: (const QModelIndex &/parent/). The /parent/ should be just comment, so the argument is just "const QModelIndex &"?
int DomModel::columnCount(const QModelIndex &/*parent*/) const { return 3; }
-
@pdsc_dy
its a not so good way of suppressing "unused parameter" warning.so yes its just
"const QModelIndex &" -
What does the "&" stand for in this case? Thanks!
-
Hi, it's a reference (a fancier type of pointer, which allows you to write parent.somevar instead of parent->somevar)
-
@pdsc_dy
One thing about references that makes them different from pointers.
They cannot be nullvoid somefunc1( someting &var )
void somefunc2( someting * var)
somefunc1(NULL) ;// will give error
somefunc2(NULL) ;// accepted
-
@mrjj said:
They cannot be null
Sure they can:
int& bar = *(int*)nullptr;
- of course it's useless, dereferencing crashes the app and it generally makes no sense but there you have it - compiling just fine :) -
@Chris-Kawa
Heh. Ok. Fair point. If you really want to. :) -
@pdsc_dy I moved your question to "C++ Gurus" forum as it is not related to Qt but to C++.
References (this & thing) are one of the C++ concepts, so you should learn C++.