What's the difference between passing by pointer and by reference?

There is a base class A.
There is a function bool foo(A &qw, A *qw2)
What is the difference, what to pass to the function, a reference to the class object, or a pointer to an object class.
In the first case the treatment is obtained qw.xx, and in the second qw2->xx.
Please explain the difference. And how more correctly.
April 19th 20 at 12:22
2 answers
April 19th 20 at 12:24
On the transfer of an object into a function — usually a link, BUT!

1. If the library lives in the pointers (Qt) pointer.
void fillCombo(QComboBox* x) {} // okay
fillCombo(ui->comboHistory);

void fillCombo(QComboBox& x) {} // bad
fillCombo(*ui->comboHistory);


2. If a possible NULL — pointer. BUT there is a pattern called "Null object", and it's good sometimes.
// Worse, but maybe
void import(AsyncRunner* asy) {
 if (asy) {
asy->run([](){
doImport(x);
});
 } else {
doImport(x);
}
}
import(nullptr);

// Better
void import(AsyncRunner& asy) {
asy.run([](){
doImport(x);
});
}
import(NoAsync::INST);


3. If transmit data buffer pointer.
void write(size_t size, const char* data) {}

4. If the object is a small value.
void save(std::string_view fileName) {}

The object could be large, but there are special registers then...
void transform(Matrix4 x) {}
There is one machine with these registers, I do not remember just what. Xbox?

5. The idiom "by value + move" to get rid of two versions of a function, Obj(string&) and Obj(string &&). Used for objects with a simple movement and complex copy — usual lines and structures of the STL.
Obj::Obj(std::string aName) : name(std::move(aName)) {}
April 19th 20 at 12:26
A pointer can be nullptr (you don't specify anything). A reference cannot be uninitialized.
When transmitting the link also displays 1234 - Angel.Trembl commented on April 19th 20 at 12:29
@Sandra_Marquar ,
In the case of the link will not work.

And what is the rationale for this assumption? Reference vs. pointer in your example there is no difference. But it is in the overall context and it's big. - Shyanne_Prohaska commented on April 19th 20 at 12:32
@Angel.Trembl, @Shyanne_Prohaska, summed residual knowledge, what to do. Strange language with strange rules \_(ツ)_/ - Sandra_Marquar commented on April 19th 20 at 12:35
changed the answer. - Sandra_Marquar commented on April 19th 20 at 12:38

Find more questions by tags C++