g++ template functions calling template functions.

Claudio Bley bley@cs.uni-magdeburg.de
Tue Jan 20 13:56:00 GMT 2004


On Mon, Jan 19, 2004 at 11:17:46AM -0800, David Sankel wrote:
> Hello all,

Hi David,
 
>   I am trying to port some msft c++ code to g++ 3.2.3 and it is generally
> going well except for this template error that I'm getting.
> 
>   I was unable to create a small example program that gives a compile error
> for the same situation.  

I'm almost certain you were just too lazy... ;-)

> It looks as though the compiler correctly resolves into the first
> version of this function (for maps).  When inside that function, the
> recursive fromDOMElement call doesn't correctly resolve to the pair
> version.  Why doesn't the compiler recognize this as the correct
> version?  It seems as though the first canidate in the error message
> matches the function call exactly.

You can't pass a temporary object to a function as a non-const
reference. (Btw, what is msft c++ and does it accept this code?)

,----[ Stroustrup: The C++ Programming Language 3rd; §7.2, 146f ]
| 
| A literal, a constant, and an argument that requires conversion can
| be passed as a const& argument, but not as a non-const argument.
| 
`----

So either define a variable explicitely and pass that to the function
if you need the function to modify it and you want to use it later or
change the functions to take a `const QDomElement&' as its first
argument.

I attached a small example with the code fixed. Please note, that this
is just a quick hack and that I needed to guess / improvise certain
things you didn't mention.

HTH
-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux user                         - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.cc
Type: text/x-c++src
Size: 2551 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20040120/e3eb9bbb/attachment.bin>


More information about the Gcc-help mailing list