Hello,
i got a strange compiler error.
When compiling the following:
// forward declarations
typedef AvlTree<LineSeg ment,LineSegmen tComperator> LSTree;
void handleEventPoin t (const EventPoint& , LSTree& , double&,
std::list<Inter sectionPoint>& );
// the interesting function
std::list<Inter sectionPoint> findIntersectio ns ( const
std::list<LineS egment*>& segments)
{
// need two data structers
AvlTree<EventPo int> eventQueue;
double offset;
LineSegmentComp erator lsc(&offset);
LSTree sweepStatus ( lsc );
//output
std::list<Inter sectionPoint> output;
// ripped some lines here
while ( ! eventQueue.isEm pty () )
{
EventPoint p = eventQueue.min( );
eventQueue.dele teElem(p);
// pass sweepStatus by reference
50: handleEventPoin t (p, sweepStatus, offset, output );
}
return output;
}
everything works fine.
But if I replace the following lines:
LineSegmentComp erator lsc(&offset);
LSTree sweepStatus ( lsc );
with this shorter version
LSTree sweepStatus ( LineSegmentComp erator(&offset) );
I always got this strange error from gcc:
geometricalgos. cpp: In function 'std::list<Inte rsectionPoint,
std::allocator< IntersectionPoi nt> > findIntersectio ns(const
std::list<LineS egment*, std::allocator< LineSegment*> >&)':
geometricalgos. cpp:50: error: invalid initialization of non-const
reference of type 'LSTree&' from a temporary of type 'LSTree
(*)(LineSegment Comperator&)'
geometricalgos. cpp:9: error: in passing argument 2 of 'void
handleEventPoin t(const EventPoint&, LSTree&, double&,
std::list<Inter sectionPoint, std::allocator< IntersectionPoi nt> >&)'
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,Compa re>::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 8 1824
grundmann wrote: LSTree sweepStatus ( lsc );
What is LineSegmentComp arater defined to be?
Somehow it would appear that sweepStatus is being
interpretted as a function declaration. This is
possible if lsc somehow itself was a type name.
grundmann wrote: Hello,
i got a strange compiler error. When compiling the following:
// forward declarations typedef AvlTree<LineSeg ment,LineSegmen tComperator> LSTree; void handleEventPoin t (const EventPoint& , LSTree& , double&, std::list<Inter sectionPoint>& );
// the interesting function std::list<Inter sectionPoint> findIntersectio ns ( const std::list<LineS egment*>& segments) { // need two data structers AvlTree<EventPo int> eventQueue; double offset; LineSegmentComp erator lsc(&offset); LSTree sweepStatus ( lsc );
//output std::list<Inter sectionPoint> output;
// ripped some lines here
while ( ! eventQueue.isEm pty () ) { EventPoint p = eventQueue.min( ); eventQueue.dele teElem(p); // pass sweepStatus by reference 50: handleEventPoin t (p, sweepStatus, offset, output ); }
return output; }
everything works fine. But if I replace the following lines:
LineSegmentComp erator lsc(&offset); LSTree sweepStatus ( lsc );
with this shorter version
LSTree sweepStatus ( LineSegmentComp erator(&offset) );
I always got this strange error from gcc: geometricalgos. cpp: In function 'std::list<Inte rsectionPoint, std::allocator< IntersectionPoi nt> > findIntersectio ns(const std::list<LineS egment*, std::allocator< LineSegment*> >&)': geometricalgos. cpp:50: error: invalid initialization of non-const reference of type 'LSTree&' from a temporary of type 'LSTree (*)(LineSegment Comperator&)' geometricalgos. cpp:9: error: in passing argument 2 of 'void handleEventPoin t(const EventPoint&, LSTree&, double&, std::list<Inter sectionPoint, std::allocator< IntersectionPoi nt> >&)'
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:
Compiler (correctly) thinks that
LSTree sweepStatus ( LineSegmentComp erator(&offset) );
is a function prototype.
Try this
LSTree sweepStatus = LSTree(LineSegm entComperator(& offset));
john
Why should the compiler think, that
LSTree sweepStatus ( LineSegmentComp erator(&offset) );
is a function prototype. Isn't it a normal declaration of a object with
calling the constructor passing the needed parameters?
I also tried your syntax before, confusing about that gcc claimed that
the copy-constructor is private. I have done this in the class AvlTree,
because copying should not be allowed. But the "Type obj = Type (
....);" syntax should not invoke the copy-constructor. The compiler
should recognise, that the rhs Object is temporary and should call the
constructor instead. I am pretty sure, that MS VC-Compiler is working
this way, but I am not sure about gcc.
@Ron:
The class LineSegmentComp erator is implemented as follows:
class LineSegmentComp erator
{
public:
explicit LineSegmentComp erator ( double* offset =0) : offset_ (offset)
{}
bool operator()(cons t LineSegment& lhs, const LineSegment& rhs);
protected:
double* offset_;
};
I am not yet understanding the error.
Best regards,
Matthias Grundmann
John Harrison schrieb: Compiler (correctly) thinks that
LSTree sweepStatus ( LineSegmentComp erator(&offset) );
is a function prototype.
Try this
LSTree sweepStatus = LSTree(LineSegm entComperator(& offset));
john
grundmann wrote: Why should the compiler think, that LSTree sweepStatus ( LineSegmentComp erator(&offset) ); is a function prototype. Isn't it a normal declaration of a object with calling the constructor passing the needed parameters?
I also tried your syntax before, confusing about that gcc claimed that the copy-constructor is private. I have done this in the class AvlTree, because copying should not be allowed. But the "Type obj = Type ( ....);" syntax should not invoke the copy-constructor. The compiler should recognise, that the rhs Object is temporary and should call the constructor instead. I am pretty sure, that MS VC-Compiler is working this way, but I am not sure about gcc.
The compiler is allowed to optimise away the copy, but the fact remains that the syntax:
A a = A(...);
Is akin to doing:
A a(A(...));
And so, the compiler must act as if the copy constructor is required, but it is private.
Ben
--
I'm not just a number. To many, I'm known as a String...
I tried this and you are right, allowing the Type AvlTree to be
copy-constructable make the compiler able to accept without any errors.
But the initial expression
LSTree sweepStatus (LineSegmentCom perator (&offset));
further leads to the error, stated above. Why?
Matthias Grundmann
grundmann wrote: I tried this and you are right, allowing the Type AvlTree to be copy-constructable make the compiler able to accept without any errors. But the initial expression
LSTree sweepStatus (LineSegmentCom perator (&offset));
further leads to the error, stated above. Why?
Matthias Grundmann
Because, as I stated, the above is a function prototype. Nothing to do
with copy constructors.
john
John Harrison wrote: grundmann wrote:
I tried this and you are right, allowing the Type AvlTree to be copy-constructable make the compiler able to accept without any errors. But the initial expression
LSTree sweepStatus (LineSegmentCom perator (&offset));
further leads to the error, stated above. Why?
Matthias Grundmann
Because, as I stated, the above is a function prototype. Nothing to do with copy constructors.
Presumably you have no trouble accepting
LSTree sweepStatus(Lin eSegmentCompera tor &offset);
as a function prototype. Presumably you also think that the extra pair
of parens makes a difference but it does not.
john
Thank you for your help. I tried this once again with intel c++ 9.0 and
got the same error. I have always thought that LineSegmentComp erator
(&offset) would be interpreted in any situations as an constructor call
returning an object and not as an declaration of a reference of type
LineSegmentComp erator. So I was wrong. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peng |
last post by:
Hi, I have encountered a simple but strange problem recently, with the STL
vector.
When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 # Argument type 'char *' does not match
expected parameter type 'const char (&)'.
names.push_back(str);
^^^
can any one tell me why? Thanks.
|
by: sriram |
last post by:
I have the following:
class BSA
{
...
...
...
...
public:
enum VRGAttrId {
|
by: Alfonso Morra |
last post by:
I have some code that I am porting over from C. It is full of static
functions and global variables. I have got around this by wrapping most
of the code in a singleton object.
However, I am findng that in my method definitions, I am having to fully
scope the names of any other functions I am calling. I do not understand
this. The clas declaration code look some thing like this:
class A: public Singleton<A> {
public:
|
by: Evangelista Sami |
last post by:
hello
i have this strange error message that i dont understand :
_search.c: In function `_depth_search':
_search.c:218: unable to find a register to spill in class `AREG'
_search.c:218: this is the insn:
(insn 83 82 84 (parallel )
(reg:SI 1 edx )))
(set (reg:SI 1 edx )
|
by: Kris Vanherck |
last post by:
yesterday i started getting this strange error when i try to run my asp.net
project:
Compiler Error Message: CS0006: Metadata file
'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net
files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f
16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be
found
| |
by: tony |
last post by:
Hello!
My question is about calling this method CollectData below but I get a
compile error that I shouldn't have because the type parameter is correct.
The compile error is the following:
C:\PK\Development\Products\UTCAS\4.0\SRC\MeltPracApplication\Dialog\Composit
ionForm.cs(942): Argument '1': cannot convert from 'ref
MeltPracData.MeltPracDataComposition' to 'ref
MeltPracCommon.IDialogPostData'
|
by: John Kotuby |
last post by:
Hi all.
I am using VS 2005 and VB.NET.
Lately as my Web Application is getting larger, I have been getting strange
compiler messages like the following:
---------------------------
Compiler Error Message: BC30560: 'controls_user_createquicksearchbar_ascx'
is ambiguous in the namespace 'ASP'.
Source Error:
|
by: Larry |
last post by:
I was testing the buffer size of system call, read(), and found a
strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
I have tried the same program on Sun Solaris 5.10 and got the same results.
|
by: =?GB2312?B?yum09MXt?= |
last post by:
today I forgot to include some header,then I found the error message by the compiler is quite strange.
so I want to know exactly the inner details of the compiler impletation,if possible.
and I want to know what does the standard say about this situation.
here is the code just to demonstrate the error.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |