template-specialization

template-specialization

文章 0 浏览 6

继承自专业化的类?

这是有效的 C++ 吗? template class any_iterator : public any_iterator { public: typedef any_iterator any_iter_void; any_iterator() : any_ite…

半边脸i 2024-12-20 10:52:34 4 0

可变参数模板的部分特化

考虑以下类模板“X”及其部分特化。 template struct X {}; // #1 template struct X {}; // #2 template struct X {}; // #3 X x; // #2 or #3 ? 我…

遗失的美好 2024-12-19 17:25:12 5 0

当我尝试部分特化函数模板时,为什么我的程序无法运行?

我是模板元编程的初学者,试图实现生成相似但略有不同的代码的多个版本: #include enum Type { a1, a2 }; enum Style { b1, b2 }; template void doS…

怪我闹别瞎闹 2024-12-19 13:50:00 5 0

定义函数模板特化的正确语法是什么?

在 C++ Primer Plus(2001,捷克语翻译)中,我发现了这些不同的模板专业化语法: 函数模板 template void foo(T); 专业化语法 void foo(int param); …

沉溺在你眼里的海 2024-12-18 20:44:35 4 0

创建专用函数模板的最佳方法是什么?

有更好的方法来执行以下操作吗? #include template T Bar(); template <> int Bar() { return 3; } // Potentially other specialisations int main(…

心作怪 2024-12-18 14:53:41 3 0

智能指针的模板专门化与普通指针完全相同

以下代码演示了该问题: template struct A { // few members and methods... }; template struct A { // different members and methods }; A ai; //…

浅紫色的梦幻 2024-12-17 06:56:51 5 0

sizeof... 是否允许在模板参数中进行专门化?

我正在尝试使用 GCC 4.7 快照做一些类似的事情: template struct foo { static const int value = 0; }; // partial specialization where n is numb…

秋千易 2024-12-16 00:06:36 5 0

为什么我似乎可以为函数模板定义部分特化?

我知道下面的代码是一个类的部分专业化: template class MyClass { … }; // partial specialization: both template parameters have same type tem…

折戟 2024-12-14 13:16:14 7 0

MSVC++2010 中的部分模板专业化(默认)

以下代码片段无法在 MSVC++2010 上编译(使用 gcc、icc 和 sun CC 可以正常编译): #include template struct Attribute { T attr[D]; }; template >…

南薇 2024-12-12 19:38:11 5 0

如何:具有派生类特定方法的派生类中的派生成员

我在 Ubuntu 11.10 和最新版本的 NetBeans 下使用 C++。假设我有 以下代码: class Node {} class DerivedNode : public Node {} class Graph { vecto…

过去的过去 2024-12-12 14:10:43 2 0

专门化 iterator_traits

我想将 std::iterator_traits、difference_type 等),我不应该修改其源代码。基本上我想做这样的事情: template struct iterator_traits::iterator>…

骄兵必败 2024-12-12 13:11:37 4 0

C++模板元编程专业化歧义

所以我刚刚开始使用模板元编程,并且我一直在编写一个字符串类。我实现了 ToString、Concat、CharAt 和 Length,没有出现太多与模板相关的问题。我试…

番薯 2024-12-12 07:44:23 6 0

定义并调用 C++专用模板的功能

我目前正在深入学习C++,我遇到了一些已经困扰了几个小时的东西。 为什么当我创建一个模板然后对其进行专门化时,我无法为专门版本调用或定义该函数?…

情域 2024-12-12 03:06:23 5 0

为什么链接器抱怨该模板中有多个定义?

当包含在至少两个翻译单元(cpp 文件)中时,这一小段代码会触发链接器的愤怒: # ifndef MAXIMUM_HPP # define MAXIMUM_HPP template T maximum(cons…

冬天旳寂寞 2024-12-11 20:26:58 3 0

C++流运算符的部分模板特化

我有一个带有友元函数的 Matrix 类,可与运算符 时)。首先在类定义中我 template friend std::ostream& operator& other); 尝试添加, friend std::o…

迷爱 2024-12-11 12:03:24 6 0
更多

推荐作者

李珊平

文章 0 评论 0

Quxin

文章 0 评论 0

范无咎

文章 0 评论 0

github_ZOJ2N8YxBm

文章 0 评论 0

若言

文章 0 评论 0

南…巷孤猫

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文