惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog
量子位
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AWS News Blog
AWS News Blog
爱范儿
爱范儿
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
Security Archives - TechRepublic
Security Archives - TechRepublic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
P
Proofpoint News Feed
V
V2EX
Martin Fowler
Martin Fowler
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
SecWiki News
SecWiki News
罗磊的独立博客
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
The Last Watchdog
The Last Watchdog

博客园 - 可可

广东电信最新DNS更新了 分布式缓存失效处理 序列化 suse中计划任务工具cron的使用 转载《.NET框架设计之五------------异常设计(异常与返回值)》 《高级Bash脚本编程指南》在线阅读 转载《Linux Shell Bash 各种小技巧》 Linux多线程例子 转载《Adding a Second IP Address to an Existing Network Adapter on Linux》 SuSE下chkconfig的启动脚本参考例子"/etc/init.d/skeleton” - 可可 - 博客园 转载《Starting and Stoping Services: insserv》 一个公网IP情况下实现LVS VS/DR vmware中suse10不能上网解决方法 Using PHP with mod_fcgid Apache Configuration PHP在Apache中两种工作方式的区别(CGI模式、Apache 模块DLL) SSO 转贴《负载均衡技术介绍》 CDN
linux下c++程序编译错误--理解typename
可可 · 2009-04-10 · via 博客园 - 可可

在linux下编译模板程序出错,出错信息如下,而同样的代码在vs2003中编译通过,google了一下原来是使用vector<T>内部类型iterator时需要添加typename,加上typename后编译通过。

meta:/var/ftp/upload/test # g++ -o temp template.cpp
template.cpp: In function ‘std::string print(std::vector<Type, std::allocator<_CharT> >)’:
template.cpp:16: error: expected `;' before ‘it’
template.cpp:17: error: ‘it’ was not declared in this scope
template.cpp: In function ‘std::string print(std::vector<Type, std::allocator<_CharT> >) [with Type = int]’:
template.cpp:29:   instantiated from here
template.cpp:16: error: dependent-name ‘std::vector<Type,std::allocator<_CharT> >::iterator’ is parsed as a non-type, but instantiation yields a type
template.cpp:16: note: say ‘typename std::vector<Type,std::allocator<_CharT> >::iterator’ if a type is meant
代码如下:

//template.cpp

#include<iostream>
#include<vector>
#include<string>
#include<sstream>

using namespace std; 

template<class Type>
string print(vector<Type> vt)
{
 stringstream ss;
 for(vector<Type>::iterator it = vt.begin(); it < vt.end(); it++)
 {
  ss << *it << " " << endl;
 }
 return ss.str();
}

int main()
{
 vector<int> vi;
 vi.push_back(100);
 vi.push_back(123);
 string str = print(vi);
 cout << str;
 return 0;
}

typename两种用法:

1。用在模板声明中,如下两个声明是一样的:

template<class T> class Widget; // uses "class"
template<typename T> class Widget; // uses "typename"

2.用于标识 nested dependent type name(嵌套依赖类型名)