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

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - ->

[Under the hood]---Matt Pietrek October 1996 MSJ [under the hood]Reduce EXE and DLL Size with LIBCTINY.LIB TN035: Using Multiple Resource Files and Header Files with Visual C++ The quick brown fox jumps over the lazy dog. [转]IOCP介绍 A simple IOCP Server/Client Class Flash for Linux CodeProject站点地图 MFC Macros and Globals (搜集)一些少走弯路的话语+参考信息 [总结]软件工程师笔试题目(C++) [转贴]35岁之前成功12条法则 C++/STL/VC资源链接(查找方便) [转贴]The Code Project Visual C++ Forum FAQ 看看你是否需要更新SYMBOL文件了?? 世界上有很多的"绳"模型 [转贴]VC:__declspec(novtable) [转贴]五个寓言故事令你受益匪浅 为什么用户自定义消息通常+0x400
[转贴][VC++6.0] 一个很深的模板Bug
-> · 2006-03-25 · via 博客园 - ->

原文地址:http://blog.vckbase.com/bruceteen/archive/2005/09/16/12160.html

#include <iostream>
using namespace std;

template <size_t n> void foo( void )
{
    cout << n << endl;
};
void bar1( void )
{
    foo<1>();
}
void bar2( void )
{
    foo<2>();
}

int main(int argc, char* argv[])
{
    bar1();
    bar2();

    return 0;
}

// 期待输出 1 2
// 实际输出 2 2
==========================
VC的开发工程师可能以为所有的人都会这么用:

#include <iostream>
using namespace std;

template <class T>
T foo( size_t n)
{
    cout << n << endl;
 return 0;
};
void bar1( void )
{
    foo<size_t>(1);
}
void bar2( void )
{
    foo<size_t>(2);
}

int main(int argc, char* argv[])
{
    bar1();
    bar2();

    return 0;
}