g++ template functions calling template functions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all,

  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've attached the compiler error that I get
formatted for easy reading.  The relevant code is as follows:

template< typename T, typename U >
void fromDOMElement( QDomElement &e, std::map<T,U> *retval, 
    const std::string &type, const std::string &name)
{
    if( 
        !e.isNull() && 
        (e.tagName() == type.c_str() ) &&
        (e.attribute("name","") == name.c_str()))
    {
        retval->clear();
        for( QDomNode i = e.firstChild(); !i.isNull(); 
            i = i.nextSibling() )
        {
            std::pair<T,U> element;
            fromDOMElement<T,U>( 
               i.toElement(), 
               &element, 
               std::string("pair"), 
               std::string("") );
            (*retval)[element.first] = element.second;
        }
    }
}

template< class T >
void fromDOMElement( QDomElement &e, std::set<T> *retval, 
    const std::string &type, const std::string &name)
{
    if( 
        !e.isNull() && 
        (e.tagName() == type.c_str() ) &&
        (e.attribute("name","") == name.c_str()))
    {
        retval->clear();
        for( QDomNode i = e.firstChild(); !i.isNull(); 
            i = i.nextSibling() )
        {
            T element;
            fromDOMElement( i.toElement(), &element, "element", "" );
            retval->insert(element);
        }
    }
}

template< typename T, typename U >
void fromDOMElement( QDomElement &e, std::pair<T,U> *retval, 
    const std::string &type, const std::string &name)
{
    if( 
        !e.isNull() && 
        (e.tagName() == type.c_str() ) &&
        (e.attribute("name","") == name.c_str()))
    {
        QDomNode i = e.firstChild(); 
        if(i.isNull())
            throw std::string("fromDOMElement with std::pair problems"); 
        fromDOMElement( i.toElement(), &retval->first, "first", "" );
        i = i.nextSibling();
        if(i.isNull())
            throw std::string("fromDOMElement with std::pair problems"); 
        fromDOMElement( i.toElement(), &retval->second, "second", "" );
    }
}

The compile error is generated when a call is made that looks like:

  fromDOMElement( QDomElement &, std::map<int,std::set<int> > , 
    const std::string &, const std::string &)

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.

Thanks in advance,

David J. Sankel

Attachment: compileError
Description: compileError


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux