What does this mean const int*& var?

It is a reference to a pointer to an int that is const.

There is another post somewhat related, actually, here. My answer gives a sorta of general algorithm to figuring these things out.

This: const int& *var has no meaning, because you cannot have a pointer to reference.

If the const’s and pointers are getting in the way, remember you can typedef these things:

typedef int* IntPointer;
typedef const IntPointer ConstIntPointer;

void foo(ConstIntPointer&); // pass by reference
void bar(const ConstIntPointer&); // pass by const reference
void baz(ConstIntPointer); // pass by value

Might make it easier to read.


If you need more help on C++, read this. More specifically, references.

References as variables do not take space:

int i; // takes sizeof(int)
int*pi = &i; // takes sizeof(int*)

int& ri = i; // takes no space.
             // any operations done to ri
             // are simply done to i

References as parameters use pointers to achieve the end effect:

void foo(int& i)
{
    i = 12;
}

void foo_transformed(int *i)
{
    *i = 12;
}

int main()
{
    int i;

    foo(i); // same as:
    foo_transformed(&i); // to the compiler (only sort of)
}

So it’s actually passing the address of i on the stack, so takes sizeof(int*) space on the stack. But don’t start thinking about references as pointers. They are not the same.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)