Re: Enum plus std::vector questions
Jack wrote:
:: "Jack" <jl@knight.com>
:: ???g???l???s?D:uXq2n14xHHA.5584@TK2MSFTNGP02.phx.gbl...
:::: Once again, I think you need a book. The & symbol has two
:::: meanings in C++:
::::
:::: FRUIT fruit(APPLE);
:::: FRUIT* pfruit = &fruit; // pointer
:::: FRUIT& rfruit = fruit; // reference
::::
:::: If pfruit is of type FRUIT*, then &pfruit is of type FRUIT**. To
:::: pass by reference, or const reference, just pass the object.
::::
:::: FRUIT fruit(APPLE);
:::: addfruit(fruit);
::::
:::: const reference is always the best way to pass an object that
:::: you do not want to be changed (though for a simple type like
:::: FRUIT passing by value is fine also).
::: Dear David,
::: One little last question, How do I convert const & object back
::: into pointers?
::: since I had the reference (const FRUIT& a) past into the method,
::: but lastly I wanted to return it as value (FRUIT* b)
::: b = a; won't compile for certain reasons. Or this is completely
::: wrong.... Thanks
::: Jack
:: Tried all of these to no avail...
:: 1) b = static_cast<FRUIT*>(a);
:: 2) b = dynamic_cast<FRUIT*>(a);
:: 3) b = reinterpret_cast<FRUIT*>(a);
:: 4) b = *a;
:: 5) b = &a;
:: all failed to compile
:: Any ideas?
Yes, it has to do with const to non-const convertion.
Bo Persson