On C++ pointers and references, clarification needed

Viewed 167

What of the below is wrong please?

It is my understanding that a pointer represents an address of something of some type.

So, int i = 18, a pointer to it is int *pI = &i;

The following 2 declarations are valid

void foo (int &something) // Will accept an address of something
void bar (int *something) // Will accept a pointer to something

When we declare a function as

void bar (int *something)

We better send a pointer to something. Indeed, foo(pI) works.

Following the same logic, when looking at

void foo (int &something)

We should send it an address of something pointing to an int as an argument, so then:

Why is foo(&i) wrong?

5 Answers
Related