[Cs3] Reminder
Mikhail Nesterenko
mikhail at cs.kent.edu
Thu Jan 18 17:07:31 EST 2018
>
> This is a reminder that I asked you a question on Tuesday about the
> difference between writing an operator++ or operator-- overload for prefix
> vs postfix.
The postfix and prefix operator signatures are made artificially to
differ by parameters. The postfix-form has a through-away parameter that is
there just to distinguish it from the prefix-form.
MyClass& operator++(); // prefix
MyClass operator++(int); // postfix
The signatures are also usually differ by the return types since the
prefix form usually returns a reference while the posfix form a
value. However, the signatures of two different functions in C++ must
differ by something other than return type. Hence, the throwaway
parameter.
>
> Also, this is a pretty random question, but I was wondering: how does auto
> work with pointers? Is a pointer to an auto different than using an auto?
> Like, say for whatever reason I wrote something like
>
> *auto a = new int(55);
>
> would that work? Or would the preferred way to do it be:
>
> *auto a = new auto("abc");
>
> Or do they both work?
auto a = new int(55); // works
auto (as of C++11) allows the compiler to automatically determine the
type of the variable on the basis of its initalizer.
auto may be augmented with const or & but not with *. That is
auto & const auto // are allowed
auto * // is not
Thanks,
--
Mikhail
More information about the cs3
mailing list