关于最新电子版《Thinking in C++(第二卷)》模板章节的一个例子的问题,模板高手请进。

flyrobbie 2003-12-30 03:57:28
在www.BruceEckel.com下载了最新版的《Thinking in C++》第二卷,“Templates in Depth”那一章中例子C05:PrintSeq.cpp,列举如下:
// A print function for standard C++ sequences
#include <iostream>
#include <list>
#include <memory>
#include <vector>
using namespace std;

template<class T, template<class U, class = allocator<U> >
class Seq>
void printSeq(Seq<T>& seq) {
for (typename Seq<T>::iterator b = seq.begin();
b != seq.end();)
cout << *b++ << endl;
}

int main() {
// Process a vector
vector<int> v;
v.push_back(1);
v.push_back(2);
printSeq(v);
// Process a list
list<int> lst;
lst.push_back(3);
lst.push_back(4);
printSeq(lst);
} ///:~
这段程序在Visual Studio.Net 2003 里编译不过。我查了一下国外的新闻组,好像是说template template parameters in functions is not allowed.但这本书没有提及啊,否则也不会列出这段程序。我想听听各位大侠的意见。
...全文
26 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hangaround 2004-01-06
  • 打赏
  • 举报
回复
dingy@szcic.com
immaga 2004-01-04
  • 打赏
  • 举报
回复
immaga@163.com
谢了!
UnrealImagecoffee 2004-01-03
  • 打赏
  • 举报
回复
我要谢谢阁下劳凡了
tool_99@163.com
zhangfjj 2004-01-03
  • 打赏
  • 举报
回复
想下第二卷,见这个贴子
http://expert.csdn.net/Expert/topic/2584/2584912.xml?temp=.3922541
Iamanders 2004-01-02
  • 打赏
  • 举报
回复
一二卷,我都有,谁要留EMAIL
只回前10位。
lcxrfddr 2004-01-02
  • 打赏
  • 举报
回复
在哪可以下载《Thinking in C++(第二卷)》,最好有CHM格式的。
xueweizhong 2003-12-31
  • 打赏
  • 举报
回复
1:
这个东东其实不是template template parameter的问题,
而是template default argument in template-argument-deduction的问题。

2:
针对当前问题,把楼主的代码重写一下,应该是这个样子:

struct t_default_arg {};
struct t_arg {};

template <typename T>
struct tt_arg {};

template
<
typename T,
template<class T1,class T2 = t_default_arg>
class TT
>
void foo(TT<T>);

int main()
{
tt_arg<t_arg> arg;
foo(arg);
}

zhaodewei_2000 2003-12-31
  • 打赏
  • 举报
回复
这段代码,我再dev_C++ 平台下是运行通过了,在VC++ 上是运行不通过得
cai114 2003-12-31
  • 打赏
  • 举报
回复
Dev-C++
是不错,

我用它学会了第一卷的所有程序

Jinhao 2003-12-31
  • 打赏
  • 举报
回复
学模板就用 Dev-C++
编译器是mingw
http://www.c-view.org/soft/devcpp/downloads/devcpp4980.exe
pyl2001 2003-12-30
  • 打赏
  • 举报
回复
模版里很多特性现在的编译器都还无法支持呢,这很正常的。你看最近出的<<C++ Templates>> 里面也有很多例子也是很多编译器还不支持的。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧