G
grundmann
Hello,
i got a strange compiler error.
When compiling the following:
// forward declarations
typedef AvlTree<LineSegment,LineSegmentComperator> LSTree;
void handleEventPoint (const EventPoint& , LSTree& , double&,
std::list<IntersectionPoint>& );
// the interesting function
std::list<IntersectionPoint> findIntersections ( const
std::list<LineSegment*>& segments)
{
// need two data structers
AvlTree<EventPoint> eventQueue;
double offset;
LineSegmentComperator lsc(&offset);
LSTree sweepStatus ( lsc );
//output
std::list<IntersectionPoint> output;
// ripped some lines here
while ( ! eventQueue.isEmpty () )
{
EventPoint p = eventQueue.min();
eventQueue.deleteElem(p);
// pass sweepStatus by reference
50: handleEventPoint (p, sweepStatus, offset, output );
}
return output;
}
everything works fine.
But if I replace the following lines:
LineSegmentComperator lsc(&offset);
LSTree sweepStatus ( lsc );
with this shorter version
LSTree sweepStatus ( LineSegmentComperator(&offset) );
I always got this strange error from gcc:
geometricalgos.cpp: In function 'std::list<IntersectionPoint,
std::allocator<IntersectionPoint> > findIntersections(const
std::list<LineSegment*, std::allocator<LineSegment*> >&)':
geometricalgos.cpp:50: error: invalid initialization of non-const
reference of type 'LSTree&' from a temporary of type 'LSTree
(*)(LineSegmentComperator&)'
geometricalgos.cpp:9: error: in passing argument 2 of 'void
handleEventPoint(const EventPoint&, LSTree&, double&,
std::list<IntersectionPoint, std::allocator<IntersectionPoint> >&)'
I don't understand this. My Object sweepStatus is not temporary, there
is no type-conversion, nor any creation of a temporary instance of
LSTree. The only thing changed is, that I pass now a temporary object
for constructor of LSTree. But the constructor is defined as follows:
template <class T, class Compare>
AvlTree<T,Compare>::AvlTree (const Compare& comp ) : root_ (0),
comp_(comp)
{
};
so the passed Compare-Object is copied to the internal member variable
comp_, which is of type Comp.
Does anybody know, where the problem is?
Best Regards,
Matthias Grundmann
i got a strange compiler error.
When compiling the following:
// forward declarations
typedef AvlTree<LineSegment,LineSegmentComperator> LSTree;
void handleEventPoint (const EventPoint& , LSTree& , double&,
std::list<IntersectionPoint>& );
// the interesting function
std::list<IntersectionPoint> findIntersections ( const
std::list<LineSegment*>& segments)
{
// need two data structers
AvlTree<EventPoint> eventQueue;
double offset;
LineSegmentComperator lsc(&offset);
LSTree sweepStatus ( lsc );
//output
std::list<IntersectionPoint> output;
// ripped some lines here
while ( ! eventQueue.isEmpty () )
{
EventPoint p = eventQueue.min();
eventQueue.deleteElem(p);
// pass sweepStatus by reference
50: handleEventPoint (p, sweepStatus, offset, output );
}
return output;
}
everything works fine.
But if I replace the following lines:
LineSegmentComperator lsc(&offset);
LSTree sweepStatus ( lsc );
with this shorter version
LSTree sweepStatus ( LineSegmentComperator(&offset) );
I always got this strange error from gcc:
geometricalgos.cpp: In function 'std::list<IntersectionPoint,
std::allocator<IntersectionPoint> > findIntersections(const
std::list<LineSegment*, std::allocator<LineSegment*> >&)':
geometricalgos.cpp:50: error: invalid initialization of non-const
reference of type 'LSTree&' from a temporary of type 'LSTree
(*)(LineSegmentComperator&)'
geometricalgos.cpp:9: error: in passing argument 2 of 'void
handleEventPoint(const EventPoint&, LSTree&, double&,
std::list<IntersectionPoint, std::allocator<IntersectionPoint> >&)'
I don't understand this. My Object sweepStatus is not temporary, there
is no type-conversion, nor any creation of a temporary instance of
LSTree. The only thing changed is, that I pass now a temporary object
for constructor of LSTree. But the constructor is defined as follows:
template <class T, class Compare>
AvlTree<T,Compare>::AvlTree (const Compare& comp ) : root_ (0),
comp_(comp)
{
};
so the passed Compare-Object is copied to the internal member variable
comp_, which is of type Comp.
Does anybody know, where the problem is?
Best Regards,
Matthias Grundmann