From: Vitaly on 31 May 2006 16:59 The code: template <template <class> class Search > class Test : public Search< Test<Search> > { public: typedef Test<Search> Parent_t; }; template <class Host> class Y { public: void Search(); }; class CallManager : public Test<Y> { }; This code successfully compiled by gcc and comeau. But if I try to compile it with VC++ (Visual Studio 2003 or Visual Studio 2005, does no matter) I get the follwoing error: error C2975: 'Search' : invalid template argument for 'Test', expected compile-time constant expression h:\test\test\test\test.cpp(18) : see reference to class template instantiation 'Test<Search>' being compiled with [ Search=Y ] I've sent the bug-report to Microsoft but there was no response. May be, I am mistaken and "this is not a bug, this is a feature", am I? It seems to me, that this code is absolutely correct... And if I rename Search member function of the template Y, everything is compiled without errors and warnings. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: André Kempe on 1 Jun 2006 07:23 Vitaly escribi?: > The code: > > template <template <class> class Search > > class Test : public Search< Test<Search> > { > public: > typedef Test<Search> Parent_t; > }; > > template <class Host> > class Y { > public: > void Search(); > }; > > class CallManager : public Test<Y> { }; Hi, just a question about something i keep wondering about. When CallManager derives from Test<Y>, and Test passes Test<Y> as template parameter, isn't this kind of an infinite loop? Greetings Andre [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Dimitar on 1 Jun 2006 16:58 Hi, Vitaly wrote: > The code: > > template <template <class> class Search > > class Test : public Search< Test<Search> > { > public: > typedef Test<Search> Parent_t; > }; > > template <class Host> > class Y { > public: > void Search(); > }; > > class CallManager : public Test<Y> { }; > Did you actually try to create instance of CallManager? If you did not probably this is why it compiled. I think Test<Y> is not correct. Y is parameterized class and you have to specify value for the template parameter. Regards, Dimitar [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bronek Kozicki on 1 Jun 2006 16:51 Vitaly <Vitaly.Repin(a)gmail.com> wrote: > This code successfully compiled by gcc and comeau. But if I try to > compile it with VC++ (Visual Studio 2003 or Visual Studio 2005, does > no matter) I get the follwoing error: > > > error C2975: 'Search' : invalid template argument for 'Test', expected > compile-time constant expression > h:\test\test\test\test.cpp(18) : see reference to class > template instantiation 'Test<Search>' being compiled > with > [ > Search=Y > ] > > I've sent the bug-report to Microsoft but there was no response. May I'm affraid that you were beaten by "Microsoft extensions". The code compiles fine if you disable them (compiler option /Za ). Unfortunatelly, these extensions (like anonymous structs nested in unions or array struct members with undefined size) are used by Windows API headers and I do not believe Microsoft is ever going to drop them. These extensions also change the way compiler performs name lookup; maybe things will improve in next version of Visual C++ (Orcas). I suppose Microsoft could submit proposal to make these extensions valid C++ (based on existing practice), but C++0x is already closed for proposals that were not discussed before. B. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Vitaly on 2 Jun 2006 18:48
Hi, Dimitar wrote > template <template <class> class Search > > class Test : public Search< Test<Search> > { > public: > typedef Test<Search> Parent_t; > }; > > template <class Host> > class Y { > public: > void Search(); > }; > > class CallManager : public Test<Y> { }; > > Did you actually try to create instance of CallManager? If you did not > probably this is why it compiled. Yes, of course. I created the instance. It's not a problem for gcc, for example. > I think Test<Y> is not correct. Y is parameterized class and you have > to specify value for the template parameter. Why? What do I have? 1) class Test with template template parameter called Search. 2) template Y. 3) template Test is instanstiated by template Y. This is correct, it seems to me. And the most interesting thing - if I rename Search memeber function of Y to (for example) MySearch, VC++ behavior becomes the same as gcc and comeau behavior - it compiles the code without errors and warnings. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |