模板相关的问题 [英] Template related question

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

问题描述

以下代码 - 来自C ++模板:完整指南通过

Vandevoorde / Josuttis - 似乎用Borland C ++编译。但是它没有用其他编译器编译
- Comeau Online和g ++。任何

想法为什么?


模板< typename T>

class Shell {

public:

模板< int N>

class In {

public:

template< int M>

class Deep {

public:

virtual void f(){}

};

};

};


模板< typename T,int N>

类奇怪{

public:

void case1(Shell< T> :: template in< N> :: template Deep< N> * p){

p-> template深< N> :: F(); //禁止虚拟通话

}

void case2(Shell< T> :: template in< T> :: template Deep< T>& p){

p.template Deep< N> :: f(); //禁止虚拟通话

}

};

谢谢。

解决方案

2004年4月8日15:42:21 -0700, lr ****** @ yahoo。 co.in (LRS Kumar)写道:

以下代码 - 来自C ++模板:完整指南通过
Vandevoorde / Josuttis - 似乎用Borland C ++编译。但是它无法与其他编译器一起编译 - Comeau Online和g ++。任何
想法为什么?

模板< typename T>
类Shell {
public:
template< int N>
class In {
public:
template< int M>
class Deep {
public void void f(){}
};
} ;
};

模板< typename T,int N>
类奇怪{
public:
void case1(Shell< T> :: template)在< N> ::模板深< N> * p){
p->模板Deep< N> :: f(); //禁止虚拟调用
}
void case2(Shell< T> :: template in< T> :: template Deep< T>& p){
p.template Deep< N> ;::F(); //禁止虚拟通话
}
};


这实际上是这本书的勘误表(我之后才发现这是

为自己搞清楚这一切,然后转到书中的第132页,

只是为了找到我已经忘记的勘误,我会写下来......)


最后一节应该说:

void case1(模板Shell< T> :: template in< N> :: template Deep< N> * p){
p->模板Deep< N> :: f(); //禁止虚拟调用
}
void case2(模板Shell< T> :: template In< N> :: template Deep< N>& p){
p.template Deep< N'GT; :: F(); //禁止虚拟通话



-leor


-

Leor Zolman --- BD软件--- www.bdsoft.com

开 - C / C ++,Java,Perl和Unix中的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html


< blockquote> 2004年4月8日15:42:21 -0700, lr ****** @ yahoo.co.in (LRS Kumar)写道:

以下代码 - 来自C ++模板:完整指南通过
Vandevoorde / Josuttis - 似乎用Borland C ++编译。但是它无法与其他编译器一起编译 - Comeau Online和g ++。任何
想法为什么?

模板< typename T>
类Shell {
public:
template< int N>
class In {
public:
template< int M>
class Deep {
public void void f(){}
};
} ;
};

模板< typename T,int N>
类奇怪{
public:
void case1(Shell< T> :: template)在< N> ::模板深< N> * p){
p->模板Deep< N> :: f(); //禁止虚拟调用
}
void case2(Shell< T> :: template in< T> :: template Deep< T>& p){
p.template Deep< N> ;::F(); //禁止虚拟通话
}
};


这实际上是这本书的勘误表(我之后才发现这是

为自己搞清楚这一切,然后转到书中的第132页,

只是为了找到我已经忘记的勘误,我会写下来......)


最后一节应该说:

void case1(模板Shell< T> :: template in< N> :: template Deep< N> * p){
p->模板Deep< N> :: f(); //禁止虚拟调用
}
void case2(模板Shell< T> :: template In< N> :: template Deep< N>& p){
p.template Deep< N'GT; :: F(); //禁止虚拟通话



-leor


-

Leor Zolman --- BD软件--- www.bdsoft.com

开 - C / C ++,Java,Perl和Unix中的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html


< blockquote> On Thu,2004年4月8日23:39:04 GMT,Leor Zolman< le ** @ bdsoft.com>写道:


Darn!我的意思是:

void case1(typename Shell< T> :: template in< N> :: template Deep< N> * p){
p->模板Deep< N> :: f(); //禁止虚拟调用
}
void case2(typename Shell< T> :: template in< N> :: template Deep< N>& p){
p.template Deep< N'GT; :: F(); //禁止虚拟通话




-leor


-

Leor Zolman --- BD软件--- www.bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD Software的免费STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html


The following code - from "C++ Templates: The Complete Guide" by
Vandevoorde/Josuttis - seems to compile with Borland C++. However it
fails to compile with other compilers - Comeau Online and g++. Any
idea why?

template<typename T>
class Shell {
public:
template<int N>
class In {
public:
template<int M>
class Deep {
public:
virtual void f(){}
};
};
};

template<typename T, int N>
class Weird {
public:
void case1(Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(Shell<T>::template In<T>::template Deep<T>& p) {
p.template Deep<N>::f(); // inhibit virtual call
}
};
Thank you.

解决方案

On 8 Apr 2004 15:42:21 -0700, lr******@yahoo.co.in (LRS Kumar) wrote:

The following code - from "C++ Templates: The Complete Guide" by
Vandevoorde/Josuttis - seems to compile with Borland C++. However it
fails to compile with other compilers - Comeau Online and g++. Any
idea why?

template<typename T>
class Shell {
public:
template<int N>
class In {
public:
template<int M>
class Deep {
public:
virtual void f(){}
};
};
};

template<typename T, int N>
class Weird {
public:
void case1(Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(Shell<T>::template In<T>::template Deep<T>& p) {
p.template Deep<N>::f(); // inhibit virtual call
}
};

This is actually in the errata for the book (which I only discovered after
figuring it all out for myself, and then turning to page 132 in the book,
only to find the errata I had forgotten I''d penciled in...)

That last section is supposed to say:
void case1(template Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(template Shell<T>::template In<N>::template Deep<N>& p) {
p.template Deep<N>::f(); // inhibit virtual call



-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


On 8 Apr 2004 15:42:21 -0700, lr******@yahoo.co.in (LRS Kumar) wrote:

The following code - from "C++ Templates: The Complete Guide" by
Vandevoorde/Josuttis - seems to compile with Borland C++. However it
fails to compile with other compilers - Comeau Online and g++. Any
idea why?

template<typename T>
class Shell {
public:
template<int N>
class In {
public:
template<int M>
class Deep {
public:
virtual void f(){}
};
};
};

template<typename T, int N>
class Weird {
public:
void case1(Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(Shell<T>::template In<T>::template Deep<T>& p) {
p.template Deep<N>::f(); // inhibit virtual call
}
};

This is actually in the errata for the book (which I only discovered after
figuring it all out for myself, and then turning to page 132 in the book,
only to find the errata I had forgotten I''d penciled in...)

That last section is supposed to say:
void case1(template Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(template Shell<T>::template In<N>::template Deep<N>& p) {
p.template Deep<N>::f(); // inhibit virtual call



-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


On Thu, 08 Apr 2004 23:39:04 GMT, Leor Zolman <le**@bdsoft.com> wrote:

Darn! I MEANT:

void case1(typename Shell<T>::template In<N>::template Deep<N>* p) {
p->template Deep<N>::f(); // inhibit virtual call
}
void case2(typename Shell<T>::template In<N>::template Deep<N>& p) {
p.template Deep<N>::f(); // inhibit virtual call



-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software''s free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


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

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