模板类中的纯虚函数 [英] pure virtual function in template class

查看:477
本文介绍了模板类中的纯虚函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否允许在模板中使用纯虚函数

基类?无论如何,我有一个工作。我在冰上溜冰了吗?

谢谢,

迈克。

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.

推荐答案

7月10日上午8:49,迈克 - 电子邮件被忽略< m_d_berger_1 ... @ yahoo.com>

写道:
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


On Thu,2008年7月10日05:53:45 -0700,puzzlecracker写道:
On Thu, 10 Jul 2008 05:53:45 -0700, puzzlecracker wrote:

7月10日上午8:49 ,迈克 - 电子邮件被忽略< m_d_berger_1 ... @ yahoo.com>

写道:
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



我不明白它是如何纯粹的,但不是会员。

无论如何,这里的代码适用于我的系统显示

正是我的意思。

迈克。


// virt_temp.cc 07/10/08

#include< iostream>

使用命名空间std;


模板< class TYP>

class BaseT

{

受保护:

BaseT(TYP x,TYP y):x_(x),y​​_(y){}

void doAll(){cout<< " x _ ="<< x_<<'',''; doChild(y _); cout<< endl;}

virtual void doChild(TYP a)= 0; //纯虚拟会员功能

私人:

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.doThings();

}

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();
}


Mike - Email Ignored写道:
Mike -- Email Ignored wrote:

On Thu,2008年7月10日05:53:45 -0700,puzzlecracker写道:
On Thu, 10 Jul 2008 05:53:45 -0700, puzzlecracker wrote:

> 7月10日,8日:早上49点,迈克 - 电子邮件被忽略< m_d_berger_1 ... @ yahoo.com>
写道:
>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.
[..]



它''太多信息确实伤害的情况。什么clacker是

告诉你的是你不能让模板成员宣布虚拟

(纯或不纯):


class foo {

template< class Tvirtual void bar(T const&); //错误

};


,这就是全部。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要'不要问

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 Tvirtual void bar(T const&); // error
};

, that''s, all.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于模板类中的纯虚函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆