PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > templates - convert nested to declaration and implementation
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
templates - convert nested to declaration and implementation

Réponse
 
LinkBack Outils de la discussion
Vieux 08/04/2008, 18h09   #1
Christopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut templates - convert nested to declaration and implementation

I have a few questions. My template class is getting very messy and I
have a need to make it more clear.
The first is how to change nested classes where the implementation is
embedded in the definition to a separate definition and
implementation. The other is, after doing the first, How can I keep
class Node hidden aside from using pimpl? I'd also like to keep the
concept of Iterator being specific to Tree, i.e Tree::Iterator and not
allow a user to declare Iterator by itself. The notion of class scope,
as it is in C#, would be nice here, but it is unavailable.



template <class T>
class Tree
{
class Node
{
T m_data
...
public:
...
T & GetData();
...
};

...
public:
...
class Iterator
{
Node * m_node;
};
...
};

  Réponse avec citation
Vieux 08/04/2008, 22h31   #2
Brian Tyler
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: templates - convert nested to declaration and implementation

I think that separating a template class interface from implementation
probably creates more problems than it is worth. A better solution might
be to work on your notation.

Try taking a look at the doxygen website (http://www.stack.nl/~dimitri/
doxygen/index.html) Doxygen is a documentation system for C++ and other
languages. I find that by using doxygen syntax to document my code it
naturally becomes clean and manageable, even in big temaplate classes. On
top of that you get a pdf of html manual documenting your code. It is a
bit of a virtuous circle.

As for the iterator, you will probably find it much easier to write it as
a separate non-nested class and then just typedef it into the class:

class iterator_for_foo {
// stuff
};

class foo {
public:
typedef iterator_for_foo iterator;
// stuff
};

For writing iterators the boost iterator library is very useful (http://
http://www.boost.org/doc/libs/1_35_0...doc/index.html)

I personally wouldn't worry about people being able to "declare Iterator
by itself." What are they going to do with it?

Brian.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h46.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10371 seconds with 10 queries