c++ - Why does sizeof a reference type give you the sizeof the type? -



c++ - Why does sizeof a reference type give you the sizeof the type? -

according standard, in [expr.sizeof] (5.3.3.2) get:

when applied reference or reference type, result size of referenced type.

this seems go along fact references unspecified [dcl.ref] (8.3.2.4):

it unspecified whether or not reference requires storage

but seems pretty unusual me have kind of inconsistency within language. regardless of whether or not reference requires storage, wouldn't of import able determine how much size reference uses? seeing these results seems wrong:

sizeof(vector<int>) == 24 sizeof(vector<int>*) == 8 sizeof(vector<int>&) == 24 sizeof(reference_wrapper<vector<int>>) == 8

what reasoning behind wanting sizeof(t&) == sizeof(t) definition?

the selection arbitrary, , trying justify either alternative lead circular metaphysical arguments.

the intent of reference (an alias for) object itself; under reasoning makes sense them both have same size (and address), , language specifies.

the abstraction leaky - reference has own storage, separate object - leading anomolies point out. have pointers when need deal "reference" separate entity object.

c++ language-lawyer

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -