Can I build a KDTree of pointers to objects?

Eric Fowler eric.fowler at gmail.com
Fri Apr 25 06:28:06 UTC 2008


This may have been a dumb question on one level: I copied those operators
out of the example. Turns out when I delete them, the program compiles, but
then when I call insert() I get a SIGSEGV in the STL headers, specifically
stl_function.h line 519. The second arg is zero; the others look fine.

517           _Result
518           operator()(_Arg1 __x, _Arg2 __y) const
519           { return _M_ptr(__x, __y); }
520         };

So I am back where I was: can I use KDTree<> in this manner? Is it intended?

Eric

On Thu, Apr 24, 2008 at 9:16 PM, Eric Fowler <eric.fowler at gmail.com> wrote:

> I have a toy app that is storing a set<> of pointers to a PlanePoint
> object, itself little more than a wrapper for {int x, y;}.
>
> Since I am storing pointers I want to store pointers in my KDTree too. With
> that in mind, I wrote this:
>
> //header PlanePoint.h:
> class PlanePoint : blah blah ..
>
> inline bool operator==(PlanePoint const * A, PlanePoint const * B);
>
> //header main.cpp:
> #include "PlanePoint.h"
> typedef KDTree::KDTree<2, PlanePoint*,
> std::pointer_to_binary_function<PlanePoint*, int, double> > tree_type_ptr;
>
> When I make I get this:
> PlanePoint.h:24: error: 'bool operator==(const PlanePoint*, const
> PlanePoint*)' must have an argument of class or enumerated type
> PlanePoint.cpp:16: error: 'bool operator==(const PlanePoint*, const
> PlanePoint*)' must have an argument of class or enumerated type
>
> This is apparently rooted in some obscure C++  - ism to the effect that you
> can't define operators for pointers, or some such thing.
>
> What I want to know is, do we have a workaround? I could just make copies
> of my object in the kdtree but would like to avoid that if at all possible.
>
> Thanks
>
> Eric
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/libkdtree-devel/attachments/20080424/bb3c032c/attachment.htm 


More information about the libkdtree-devel mailing list