Prev: Tree container library
Next: Atexit() and C++
From: Thomas Tutone on 26 Jan 2006 20:38 Alberto Ganesh Barbati wrote: > Thomas Tutone ha scritto: > > mikehcox(a)gmail.com wrote: > >> Below is a file I'm getting compile errors on (CASEs 1 and 2). I think > >> both 1 and 2 should be legal C++. Visual C++ Expres 2005 agrees with > >> me. Compiling using Cygwin's GNU 3.4.4 has the shown error messages. > >> Which compiler is right and what C++ standard clause would cover this > >> situation? > > > > Comeau online (which is what I always check when I have questions like > > this) agrees with gcc, so I'm voting with gcc on this one. > > You compiled in "relaxed mode". Actually, I compiled in "strict mode." >If you choose "strict mode" it gives you > three errors, as I would expect: It appears you misunderstood my post. The OP said that Visual C++ 2005 compiled without errors, but that gcc showed errors. I said that Comeau agreed with gcc, so I thought gcc was right. And it appears, unless I've misunderstood _your_ post - and perhaps I'm overlooking some subtlety - that you agree with my assessment as well. Best regards, Tom [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: mikehcox on 27 Jan 2006 21:40 Thanks for the very through response (and other responders too). Is there any way to "inject" the namespace of the base class into the template class? In the original code that this is derived from, I have *many* typedefs in the base class that I would like to use in the deriving template class (think STL container typedefs). The way things stand now I have to redeclare each typedef in the derived template class. And since users of this class most likely will be deriving yet another template class from this derived template class, they will *also* have to redeclare these typedefs. Is there any way (maybe a "using" statement of some sort?) that I can "batch" the redeclaration of these typedefs? Is there some meta-template trick that would allow me to achieve this? I sure hope the C++ standards committee's goal to make C++ easier to learn/more accessible includes something to make this template namespace design simpler. I keep tripping up on this issue ... Thanks again, Mike [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: kanze on 30 Jan 2006 05:55 mikehcox(a)gmail.com wrote: > Is there any way to "inject" the namespace of the base class > into the template class? Not that I know of (supposing that the base class is a template instantiation which depends on a parameter of the template class.) > In the original code that this is derived from, I have *many* > typedefs in the base class that I would like to use in the > deriving template class (think STL container typedefs). The > way things stand now I have to redeclare each typedef in the > derived template class. And since users of this class most > likely will be deriving yet another template class from this > derived template class, they will *also* have to redeclare > these typedefs. Is there any way (maybe a "using" statement > of some sort?) that I can "batch" the redeclaration of these > typedefs? Is there some meta-template trick that would allow > me to achieve this? I'm not too strong in meta-programming, so I can't say for sure, but a priori, I don't see one. You can make the job easier for derived classes by providing a macro. Something along the lines of: #define PROVIDE_BASECLASS_TYPES( Derived, TypedefClass ) \ typedef base_nested_typedef< Derived, TypedefClass > \ Base ; \ typedef typename Base::nested_type \ nested_type ; \ ... \ > I sure hope the C++ standards committee's goal to make C++ > easier to learn/more accessible includes something to make > this template namespace design simpler. I keep tripping up on > this issue ... You're not the only one. The issue is further complicated by the fact that not all compilers fully implement two phase lookup. Which means that just trying the code out with a compiler doesn't necessarily help. (It also means that those of us who started using templates earlier have gotten into bad habits.) -- James Kanze GABI Software Conseils en informatique orient?e objet/ Beratung in objektorientierter Datenverarbeitung 9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: David Abrahams on 30 Jan 2006 16:45
mikehcox(a)gmail.com writes: > Thanks for the very through response (and other responders too). > > Is there any way to "inject" the namespace of the base class into the > template class? In the original code that this is derived from, I have > *many* typedefs in the base class that I would like to use in the > deriving template class (think STL container typedefs). The way things > stand now I have to redeclare each typedef in the derived template > class. And since users of this class most likely will be deriving yet > another template class from this derived template class, they will > *also* have to redeclare these typedefs. Is there any way (maybe a > "using" statement of some sort?) that I can "batch" the redeclaration > of these typedefs? Is there some meta-template trick that would allow > me to achieve this? Just access them with qualification: template <class B> class D : B { typedef D self; // now use self::type1, self::type2, etc. }; -- Dave Abrahams Boost Consulting www.boost-consulting.com [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |