Koder 228
Koder 228

Reputation: 200

Double ampersand in C++. (First declaration on func params, second - before the variables)

Sorry for my low level of English. I have one question.

QDataStream &operator<<(QDataStream &out, PbxCfgHeader &info)
{
    out.writeRawData((char*)&info, sizeof(info));
    return out;
}

In the code above, a record (char*)&info equivalent T &&? Thank you

Upvotes: 2

Views: 144

Answers (1)

melpomene
melpomene

Reputation: 85867

The & in the parameter list (or in any declaration) is unrelated to the use of & in expressions. (The syntax is unfortunate.)

In a declaration &foo means "I'm declaring foo as a reference" (i.e. an alias for another variable).

In an expression &foo means "I'm taking the address of foo" (i.e. the result is a pointer to foo).

The two are very different, and they don't "stack". &info in your code does not have type PbxCfgHeader && (and that double && is yet another thing called an r-value reference).

Upvotes: 2

Related Questions