Re: Reference Type
On Mar 25, 2:28 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
baibaichen wrote:
I test the following codes in VC++ and GCC
const std::string& str = "";
std::cout << typeid(str).name() << std::endl;
std::cout << typeid(const std::string&).name()<< std::endl;
std::cout << typeid(const std::string).name()<< std::endl;
Both think str, const std::string& and const std::string are
the same type!
Aren't str and const std::string& reference type?
There's no such a thing as a "reference type" (as opposed to
other types). A reference is simply an "alias" to something,
and it behaves exactly like that something. Its type is that
of that something.
The standard speaks of reference types. I think what you're
trying to get at is that references aren't objects; they are
simply aliases for other objects.
That is, at least, how the stanard presents it. On the other
hand, in the preable to expression (section 5, paragraph 6), it
says that "if an expression initially has the type `reference to
T', the type is adjusted to `T' prior to any further analysis."
Except, of course, that an expression which initially has a
reference type is always an lvalue.
In sum: references are types, but they aren't types, depending.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34