![]() |
pure virtual function in template class
Is a pure virtual function in allowed in a template
base class? In any case, I have one working. Am I skating on thin ice? Thanks, Mike. |
Re: pure virtual function in template class
On Jul 10, 8:49 am, Mike -- Email Ignored <m_d_berger_1...@yahoo.com>
wrote: > Is a pure virtual function in allowed in a template > base class? In any case, I have one working. Am I > skating on thin ice? > Thanks, > Mike. Yes, it can be in the template class, but it can NOT be a virtual template member function |
Re: pure virtual function in template class
On Thu, 10 Jul 2008 05:53:45 -0700, puzzlecracker wrote:
> On Jul 10, 8:49 am, Mike -- Email Ignored <m_d_berger_1...@yahoo.com> > wrote: >> Is a pure virtual function in allowed in a template base class? In any >> case, I have one working. Am I skating on thin ice? >> Thanks, >> Mike. > > > Yes, it can be in the template class, but it can NOT be a virtual > template member function I don't understand how it could be pure, but not a member. In any case, here is code that works on my system showing exactly what I mean. Mike. // virt_temp.cc 07/10/08 #include <iostream> using namespace std; template <class TYP> class BaseT { protected: BaseT(TYP x,TYP y) : x_(x),y_(y){} void doAll(){cout << "x_="<<x_<<',';doChild(y_);cout<<endl;} virtual void doChild(TYP a)=0;// pure virtual member function private: TYP x_; TYP y_; }; class Child : protected BaseT<int> { public: Child() : BaseT<int>(1,2){} void doThings(){doAll();} private: virtual void doChild(int a); }; void Child::doChild(int a){cout<<"a="<<a;} int main(int argc, const char* argv[]) { Child child; child.doThings(); } |
Re: pure virtual function in template class
On Thu, 10 Jul 2008 10:56:16 -0400, Victor Bazarov wrote:
[...] > > It's the case when too much information actually hurt. What clacker is > telling you is that you can't have a template member declared virtual > (pure or not): > > class foo { > template<class T> virtual void bar(T const&); // error > }; > > , that's, all. > > V Then my working example is just dumb luck? Or might it be a non-standard gnu add-on? Mike. |
Re: pure virtual function in template class
On Thu, 10 Jul 2008 12:48:36 -0400, Victor Bazarov wrote:
> Mike -- Email Ignored wrote: >> On Thu, 10 Jul 2008 10:56:16 -0400, Victor Bazarov wrote: >> >> [...] >>> It's the case when too much information actually hurt. What clacker >>> is telling you is that you can't have a template member declared >>> virtual (pure or not): >>> >>> class foo { >>> template<class T> virtual void bar(T const&); // error >>> }; >>> >>> , that's, all. >>> >>> V >> >> Then my working example is just dumb luck? > > "Dumb luck"? I am not sure how that is applicable here. Your example > has no virtual functions that are member templates. Then what is my function: virtual void doChild(TYP a)=0;// pure virtual member function Why is this ok? [...] Mike. |
Re: pure virtual function in template class
On Thu, 10 Jul 2008 13:28:40 -0400, Victor Bazarov wrote:
> Mike -- Email Ignored wrote: [...] >> >> Then what is my function: >> >> virtual void doChild(TYP a)=0;// pure virtual member function > > It's a pure virtual function, a member of the class template. Since it > is a member of a template, it is a template itself, but it's not a > member template. It's a template member. Confusing, isn't it? > [...] Yes, thanks, it is clear now (pardon my laughter). Is there somewhere is the standard I might see this? Mike. |
Re: pure virtual function in template class
On Jul 10, 2:49 pm, Mike -- Email Ignored <m_d_berger_1...@yahoo.com>
wrote: > Is a pure virtual function in allowed in a template base > class? In any case, I have one working. Am I skating on thin > ice? No. Why should there be any problem? The instantiation of a class template is just like any other class. The same rules apply. -- James Kanze (GABI Software) email:james.kanze@gmail.com 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 |
Re: pure virtual function in template class
On Fri, 11 Jul 2008 02:08:45 -0700, James Kanze wrote:
> On Jul 10, 2:49 pm, Mike -- Email Ignored <m_d_berger_1...@yahoo.com> > wrote: >> Is a pure virtual function in allowed in a template base class? In any >> case, I have one working. Am I skating on thin ice? > > No. Why should there be any problem? The instantiation of a class > template is just like any other class. The same rules apply. How about, then, a template class virtual member function that is not pure? It is my understanding that such a virtual function may not be inline, but, at least on the gnu c++ compiler, non-pure functions of a template class must be inline (unless there have been recent developments I do not know about). Mike. |
Re: pure virtual function in template class
On Jul 13, 3:36 am, Mike -- Email Ignored <m_d_berger_1...@yahoo.com>
wrote: > On Fri, 11 Jul 2008 02:08:45 -0700, James Kanze wrote: > > On Jul 10, 2:49 pm, Mike -- Email Ignored <m_d_berger_1...@yahoo.com> > > wrote: > >> Is a pure virtual function in allowed in a template base > >> class? In any case, I have one working. Am I skating on > >> thin ice? > > No. Why should there be any problem? The instantiation of > > a class template is just like any other class. The same > > rules apply. > How about, then, a template class virtual member function that > is not pure? Again, the same rules apply as with any other class. No problem. > It is my understanding that such a virtual function > may not be inline, Why not? One idiom (which used to be common, before templates) even requires them to be inline. > but, at least on the gnu c++ compiler, non-pure functions of a > template class must be inline (unless there have been recent > developments I do not know about). Nonsense. G++ has never had this restriction. -- James Kanze (GABI Software) email:james.kanze@gmail.com 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 |
| All times are GMT. The time now is 04:49 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.