C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Template qui ne s'intancie pas ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Pierre THIERRY
Guest





PostPosted: Sat Jun 03, 2006 1:48 am    Post subject: Template qui ne s'intancie pas ? Reply with quote



Hello,

j'ai un petit souci avec une fonction template. Voilà mon code, sachant
que TreeFactory<T, U>::Tree est un typedef sur boost::variant<int,
Node*, Leaf*>, Node et Leaf étant des classes définies dans
TreeFactory<T, U>...

------------------------------------------------------------------------
#include <iostream>
#include <boost/variant/get.hpp>
#include "twotypestree.h"

using namespace std;
using namespace boost;
using namespace twotypestree;

template<typename T, typename U> void stream_tree(ostream& out, const typename TreeFactory<T, U>::Tree& tree)
{
try
{
typedef typename TreeFactory<T, U>::Node* Node_ptr;
Node_ptr node = get<Node_ptr>(tree);
out << node->get_payload() << "( ";
stream_tree(out, node->get_left());
out << " , ";
stream_tree(out, node->get_right());
out << " )";
}
catch (bad_get) {}

try
{
typedef typename TreeFactory<T, U>::Leaf* Leaf_ptr;
Leaf_ptr leaf = get<Leaf_ptr>(tree);
out << leaf->get_payload();
}
catch (bad_get) {}
}

int main(int argc, char** argv)
{
TreeFactory<int, float> factory;

TreeFactory<int,float>::Tree leaf1 = factory.leaf(5.5);
TreeFactory<int,float>::Tree leaf2 = factory.leaf(4.5);
TreeFactory<int,float>::Tree node = factory.node(0, leaf1, leaf2);

stream_tree(cout, node);
cout << endl;
}
------------------------------------------------------------------------

Mon problème est qu'à la compilation (gcc 4.0.4 20060507 prerelease),
j'obtiens l'erreur suivante :

test.cpp:42: erreur: no matching function for call to 'stream_tree(std::ostream&, boost::variant<twotypestree::Tree_Placeholder, twotypestree::TreeFactory<int, float>::Node*, twotypestree::TreeFactory<int, float>::Leaf*>&)'

(en fait, le variant comprend encore une tripotée d'argument template,
mais j'ai coupé)

Et je ne vois pas ce qui manque pour qu'il trouve ladite fonction, a
priori pourtant sous son nez.

Confusément,
Nowhere man
--
nowhere.man (AT) levallois (DOT) eu.org
OpenPGP 0xD9D50D8A
Back to top
Pierre THIERRY
Guest





PostPosted: Sun Jun 04, 2006 5:19 am    Post subject: Re: Template qui ne s'intancie pas ? Reply with quote



Le Fri, 02 Jun 2006 22:48:52 +0200, Pierre THIERRY a écrit :
Quote:
template<typename T, typename U> void stream_tree(ostream& out, const typename TreeFactory<T, U>::Tree& tree)
{
try
{
typedef typename TreeFactory<T, U>::Node* Node_ptr;
Node_ptr node = get<Node_ptr>(tree);
out << node->get_payload() << "( ";
stream_tree(out, node->get_left());
out << " , ";
stream_tree(out, node->get_right());
out << " )";
}
catch (bad_get) {}

Toutes mes excuses, j'ai lu les messages d'erreur trop vite, sans faire
vraiment attention aux numéros de ligne. Le problème était bien sûr que
j'appelais stream_tree(...) au lieu de stream_tree<T,U>(...).

Honteusement,
Nowhere man
--
nowhere.man (AT) levallois (DOT) eu.org
OpenPGP 0xD9D50D8A
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.