Question regarding use of C++0x auto keyword
I was reading about the new auto keyword in C++0x and wondered about
its behavior in the following situation.
I have occasionally written classes like this (massively simplified):
class myclass
{
private:
struct converter
{
converter(int n) : n_(n) { /*empty*/ }
operator int() { return(n_); }
};
public:
converter getSomething() { return(converter(5)); }
};
int main()
{
myclass mc;
int n = mc.getSomething();
return(0);
}
now, say we change main() to use the auto keyword as follows:
int main()
{
myclass mc;
auto n = mc.getSomething();
return(0);
}
The local 'n' is now of type struct converter. When I compile this
using the Comeau test drive compiler it compiles without complaint.
Should it? It seems to me that auto should just cause the compiler
to determine the type of the expression "mc.getSomething()" but that
it then should compile as if 'auto' were replaced by that type and
so the compile should generate an error because 'struct converter'
is not accessible (being private).
I've browsed the latest C++0x working paper but was unable to find
any place where the exact semantics of auto were defined in terms
of name lookup, etc.
Can anyone explain to me the correct behavior here?
Thanks,
-m
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]