POV-Ray : Newsgroups : povray.off-topic : Smart little programming tricks, where to find ? : Re: Smart little programming tricks, where to find ? Server Time
10 Oct 2024 23:18:31 EDT (-0400)
  Re: Smart little programming tricks, where to find ?  
From: Warp
Date: 20 Mar 2008 17:19:10
Message: <47e2e2dd@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.