使用朋友和模板类 [英] using friend and template class

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

问题描述




是一种类似以下的结构:


模板< class view_model>

class template_clase

{

protected:

template_clase(){}

virtual~template_clase(){} < br $>
};


clase friend_class

{

friend_class(){}

virtual~friends_class {}

朋友template_class;

};


我的编译(Visual C ++ 7.0)不接受此代码。是否有可能和

如果是,如何使用模板类作为朋友类?


提前谢谢

Sebastian

Hi,

is a construction like the following possible:

template<class view_model>
class template_clase
{
protected:
template_clase() {}
virtual ~template_clase() {}
};

clase friend_class
{
friend_class() {}
virtual ~friend_class{}

friend template_class;
};

My compile ( Visual C++ 7.0 ) doesn''t accept this code. Is it possible and
if yes how, to use a template class as a friend class?

Thanks in advance
Sebastian

推荐答案

Sebastian Faust写道:
Sebastian Faust wrote:


是一种类似以下的结构:

模板< class view_model>
class template_clase
{
protected:
template_clase(){}
virtual~template_clase(){朋友模板_class,朋友模板;
};

我的编译(Visual C ++ 7.0)不接受此代码。是否可以,如果是,如何使用模板类作为朋友类?
Hi,

is a construction like the following possible:

template<class view_model>
class template_clase
{
protected:
template_clase() {}
virtual ~template_clase() {}
};

clase friend_class
{
friend_class() {}
virtual ~friend_class{}

friend template_class;
};

My compile ( Visual C++ 7.0 ) doesn''t accept this code. Is it
possible and if yes how, to use a template class as a friend class?




没有模板类这样的东西。有类模板。阅读

这两句话,直到你掌握了差异。类模板是

* only * templates。他们不是班级。所以他们不能成为朋友。


此外我不明白为什么你打电话给班级给朋友

访问friend_class?在C ++中,我们称朋友类为* *给予*

友谊。此外,您有template_clase和template_class。我认为这是一个错字。


-

WW aka Attila



There is no such thing as template class. There are class templates. Read
this two sentences until you grasp the difference. Class templates are
*only* templates. They are not classes. So they cannot be made friends.

Furthermore I do not understand that why do you call the class giving friend
access friend_class? In C++ we call friend class the class *being given*
the friendship. Furthermore you have template_clase and template_class. I
assume this is a typo.

--
WW aka Attila





此代码有效(VC ++ 7.1):

模板< class view_model> class template_clase


{


受保护:


template_clase(){}


virtual~template_clase(){}


};


class friend_class

{


friend_class(){}

virtual~friends_class(){}


朋友类template_clase< class view_model> ;; //这是一个

模板!!!!


};


: - ))


玩得开心,


Viatcheslav。


" Sebastian Faust" < SF ************* @ logic-software.de>在消息中写道

news:bl ************* @ news.t-online.com ...
Hi,

This code is works (VC++ 7.1):
template<class view_model> class template_clase

{

protected:

template_clase() {}

virtual ~template_clase() {}

};

class friend_class

{

friend_class() {}

virtual ~friend_class() {}

friend class template_clase<class view_model>; // this is a
template!!!!

};

:-))

Have fun,

Viatcheslav.

"Sebastian Faust" <sf*************@logic-software.de> wrote in message
news:bl*************@news.t-online.com...


是一种类似以下的结构:

模板< class view_model>
class template_clase
{
protected:
template_clase( ){}
虚拟~template_clase(){}
};

分段friend_class
{
friend_class(){}
虚拟〜 friend_class {}

朋友template_class;
};

我的编译(Visual C ++ 7.0)不接受这段代码。是否有可能和
如果是,如何使用模板类作为朋友类?

提前致谢
Sebastian
Hi,

is a construction like the following possible:

template<class view_model>
class template_clase
{
protected:
template_clase() {}
virtual ~template_clase() {}
};

clase friend_class
{
friend_class() {}
virtual ~friend_class{}

friend template_class;
};

My compile ( Visual C++ 7.0 ) doesn''t accept this code. Is it possible and
if yes how, to use a template class as a friend class?

Thanks in advance
Sebastian





" WW" < WO *** @ freemail.hu>在消息中写道

news:bl ********** @ phys-news1.kolumbus.fi ...

"WW" <wo***@freemail.hu> wrote in message
news:bl**********@phys-news1.kolumbus.fi...
Sebastian Faust写道:
Sebastian Faust wrote:


是一种类似以下的结构:

模板< class view_model>
class template_clase
{
protected:
template_clase(){}
virtual~template_clase(){}
};

clase friend_class
{
friend_class( ){}
虚拟〜朋友_class {}
朋友template_class;
};

我的编译(Visual C ++ 7.0)不接受这个码。是否可能,如果是,如何使用模板类作为朋友类?
没有模板类这样的东西。有类模板。
Hi,

is a construction like the following possible:

template<class view_model>
class template_clase
{
protected:
template_clase() {}
virtual ~template_clase() {}
};

clase friend_class
{
friend_class() {}
virtual ~friend_class{}

friend template_class;
};

My compile ( Visual C++ 7.0 ) doesn''t accept this code. Is it
possible and if yes how, to use a template class as a friend class?
There is no such thing as template class. There are class templates.



阅读这两句话,直到你掌握了差异。类模板仅用于*模板。他们不是班级。所以他们不能成为朋友。


1.至少在定义上我们称之为template< typename X> Y级。 :-))

2.两个模板类和类是数据抽象。

3.两个抽象都有可见性规则(公共,受保护,私有)

数据/方法。

4.对于一些其他抽象(无关紧要 - 模板类,

类,函数)我们可以允许忽略可见性规则。 (这是

什么朋友用于:-)))


5.因此:模板类没有逻辑原因无法制作

的朋友。


Viatcheslav。

此外我不明白为什么你打电话给班级给
朋友访问friend_class?在C ++中,我们称朋友类为* *给予友谊。此外,您有template_clase和template_class。
我认为这是一个错字。

- WW aka阿提拉


Read this two sentences until you grasp the difference. Class templates are
*only* templates. They are not classes. So they cannot be made friends.
1. At least at definition we call it "template <typename X> class Y". :-))
2. Both "template classes" and "classes" are data abstractions.
3. Both abstractions has visibility rules (public, protected, private) for
data/methods.
4. For some other abstractions (does not matter - "template classes",
"classes", "functions") we can allow to neglect visibility rules. (This is
what "friend"(s) are for :-)) )

5. Therefore: there is no logical reason that template classes can not made
friends.

Viatcheslav.

Furthermore I do not understand that why do you call the class giving friend access friend_class? In C++ we call friend class the class *being given*
the friendship. Furthermore you have template_clase and template_class. I assume this is a typo.

--
WW aka Attila



这篇关于使用朋友和模板类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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