I'm trying to implement a templated class that contains a templated method.
template <class T1, class T2, class T3, class T4>
class ReferenceXML
{
public:
template <class T>
static tinyxml2::XMLElement* addChildAtEnd
(
tinyxml2::XMLElement* parent,
const std::string& name,
const T& value
);
}; // end class definition
template<class T>
template < class T1, class T2, class T3, class T4>
tinyxml2::XMLElement* ReferenceXML<T1,T2,T3,T4>::addChildAtEnd(
tinyxml2::XMLElement* parent,
const std::string& name,
const T& value
)
{
tinyxml2::XMLElement* element = addChildAtEnd( parent, name );
if ( element == NULL )
{
return NULL;
}
std::stringstream ss;
ss << value;
tinyxml2::XMLText* value_ptr = element->GetDocument()->NewText( ss.str().c_str() );
element->InsertFirstChild( value_ptr );
return element;
}
The error I'm getting is the following : 1>c:\projects\ufm_integration_adtf\trunk\testfilters\xmlexporter\sources\xmlexporter_ref_objdesc\sources\referencexml.h(278): error C2244: 'ReferenceXML::addChildAtEnd' : unable to match function definition to an existing declaration
1> definition
1> 'tinyxml2::XMLElement *ReferenceXML::addChildAtEnd(tinyxml2::XMLElement *,const std::string &,const T &)'
1> existing declarations
1> 'tinyxml2::XMLElement *ReferenceXML::addChildAtEnd(tinyxml2::XMLElement *,const std::string &,const T &,const std::string &)'
1> 'tinyxml2::XMLElement *ReferenceXML::addChildAtEnd(tinyxml2::XMLElement *,const std::string &,const T &)' 1> 'tinyxml2::XMLElement *ReferenceXML::addChildAtEnd(tinyxml2::XMLElement *,tinyxml2::XMLElement *)' 1> 'tinyxml2::XMLElement *ReferenceXML::addChildAtEnd(tinyxml2::XMLElement *,const std::string &)'
I don't understand why the definition doesn't get matched to one of the existing declarations, can anyone help ? Thank you.
Just swapping the templates in the definition seems to fix the issue:
template < class T1, class T2, class T3, class T4>
template < class T >
XMLElement* ReferenceXML<T1,T2,T3,T4>::addChildAtEnd(
That way, the template order in your declaration matches your definition.