作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
从全局命名空间获取模板名称时,您可以使用 template
关键字:
template <class T> void function_template();
template <class T>
void h()
{
::template function_template<T>();
}
int main() { h<int>(); }
但是这段代码可以在没有它的情况下编译。在什么情况下可能需要这样做?
最佳答案
我能想到一个地方,但我认为它不太常见:
#include <iostream>
// simpile function template
template<class T>
void function_template(T)
{
std::cout << __PRETTY_FUNCTION__ << '\n';
}
// overload (NOT specialized)
void function_template(int value)
{
std::cout << __PRETTY_FUNCTION__ << '\n';
}
int main()
{
function_template(0); // calls overload
::function_template(0); // calls overload
::template function_template(0); // calls template, deduces T
}
输出
void function_template(int)
void function_template(int)
void function_template(T) [T = int]
我打算将其中的一些内容填充到一个匿名命名空间中,以实际为 ::
带来重要意义,但这似乎已经足够了,所以我将其遗漏了。
关于c++ - 有没有理由使用 "::template"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28007081/
您好,我希望我的下一个输出(在本例中就是字母)在上一个输出之后输出 8 个空格。这适用于第一个字符,但之后的 printf 语句不起作用。它在第一个 printf 语句之后立即打印,我试图将其设置为
我想知道制作 std::list<>::splice 背后的基本原理是什么使引用被拼接到新容器中的子序列的迭代器无效。这对我来说有点不合逻辑,尤其是考虑到标准 std::container::swap
谁能告诉我为什么我应该使用 Azure Function 输出绑定(bind)(例如 SendGrid 或 Twilio)而不是仅仅在我的 C# 函数中显式使用适当的 SDK(例如 Sendgrid
我们在当前项目中使用 React 和 TypeScript,我遇到了以下行为。 import React, { Component } from 'react'; 我将上面的行替换为下面的行,因为它似
我是一名优秀的程序员,十分优秀!