|
|
Warp <war### [at] tagpovrayorg> wrote:
> Nicolas Alvarez <nic### [at] gmailisthebestcom> wrote:
> > Oh I think I know. I took a while without noticing anything wrong, but
> > now I remember having read about it in C++ FAQ Lite. theMap(Comp())
> > *declares a function* instead of instantiating an object.
> But why? Doesn't "Comp()" create an object? How can you declare a function
> with an object (instead of a type)?
> What kind of function? What does it return? Does it take parameters?
> What is the type of those parameters?
Nobody probably cares, but the answer is:
std::map<A, int, Comp> theMap(Comp());
declares a function called 'theMap' which returns a value of type
std::map<A, int, Comp> and takes one parameter: A pointer to a function
which takes no parameters and which returns a value of type Comp.
The reason *why* this is so is apparently because of backwards
compatibility with old C code, and something the C++ standardization
committee really didn't want to include in the standard, but they had
little alternatives (lest they break a lot of existing code).
--
- Warp
Post a reply to this message
|
|