On 23 Dec 2003 02:28:51 -0800,
coolpint@yahoo.co.uk (CoolPint) wrote:
[color=blue]
>I have implemented a generic priority queue below and tested it works
>fine, but I have one small problem I cannot understand. I have type
>parameter F which determines the priority so that users can
>instantiate in the following ways
>
>PQueue<int> pq1;
>PQueue<int, Functor> pq2; // where Functor is a name of user-defined
>class
>
>I also added another constructor to accept a function pointer so that
>users can use normal functions as callback too. For example,
>
>PQueue<int, bool (*) (int, int)> pq3(function);
>// where function is a user-defined function which accepts ints and a
>bool
>
>So far so good. I then got a bit curious and issued something like
>this:
>
>PQueue<int, Functor> pq4(Functor()); <------- This causes the error[/color]
That's a function declaration! (a function called pq4 taking a Functor
and returning a PQueue<int, Functor>). I think you meant:
//extra parentheses prevent parsing as function decl
PQueue<int, Functor> pq4((Functor()));
or
// named object also works.
Functor f;
PQueue<int, Functor> pq4(f);
Tom
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html