- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这可能是新手的错误,我正在使用 Microsoft Visual C++ 编译器 2012 年 11 月 CTP,当我尝试编译它时:
#include <tuple>
class A
{
public:
template <class... Fs, template <class...> class T>
void foo(T<Fs...>);
};
template <class... Fs, template <class...> class T>
void A::foo(T<Fs...>)
{
}
int main()
{
A a;
a.foo(std::make_tuple(10,10));
}
我收到以下错误:
error C2244: 'A::foo' : unable to match function definition to an existing declaration
definition
'void A::foo(T<Fs...>)'
existing declarations
'void A::foo(T<Fs...>)'
如果我内联它编译的函数并做我想做的事,但我必须将函数放在头文件中
但是下面的代码编译没有错误:
#include <vector>
class A
{
public:
template <class Fs, template <class> class T>
void foo(T<Fs>);
};
template <class Fs, template <class> class T>
void A::foo(T<Fs>)
{
}
int main()
{
A a;
a.foo(std::vector<int>());
}
所以问题是我怎样才能用可变参数模板实现同样的事情
编辑:
按照建议在 Microsoft Connect 上提交错误报告 ID :771567
vector 示例也很糟糕(它会给出 <std::_Simple_types<int>,std::_Vector_val>
,但它确实可以编译),但是如果你尝试使用一对和模板参数:
template <class F, class G, template <class,class> class T>
你会得到<F,G,std::pair>
这就是我的意思
最佳答案
From MSDN regarding Compiler Error C2244 :
You cannot partially specialize a function template.
我还认为你必须在类前面声明模板
:
template<typename T>
class MyClass
{
};
关于c++ - VC++ Variadic-Template-Template 错误 C2244 : unable to match function definition to an existing declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433196/
我试图创建一个模板,给定一组元函数和一个元函数,将这个元函数添加到提供的集合中。 template class...> class Dest, template c
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
考虑以下代码 #define COMB(F, ...) F(__VA_ARGS__) #define ADD(X, Y) (X + Y) int foo() { return COMB(ADD
以下代码可以编译,因为我假设 parent的 Object本身没有 parent 。 template struct Object { T item; // T is item's typ
我目前正在研究一些新的 C++17 特性,特别是 std::optional,我决定尝试找到一个最小值使用可变参数模板的函数。这是我目前所拥有的: template typename Opt,
我想知道是我做错了什么还是编译器错误。我正在使用 Intel C++ Composer XE 2011 for Windows SP1(或更新 6,目前是最新的)。请参阅代码中的注释行。 #inclu
阅读可变参数函数时,我发现了一个 sum 函数,它接受任意数量的任意数字类型并计算它们的总和。 具有此函数的模板化特性,我希望它接受 string 对象,因为运算符 + 是为字符串定义的。 #incl
在 2012 ACCU C++ Pub quiz 的第 15 个问题中,我被结果难住了。 #include template void P(T x) { std::cout // foo 2 v
我在这里遗漏了一些关于类型推导的非常基本的东西: 我正在尝试编写一个包装函数,它调用一个带有 nullptr 的编写器函数以获得所需的长度,然后调整缓冲区大小,然后再次调用该函数,现在使用调整大小的缓
如何创建两个 VARIADIC 参数。查看我的代码并纠正我。 CREATE OR REPLACE FUNCTION ip_source_test(text,text,date,date,VARIADI
我希望创建一个类来检查两个参数类型列表,以查看是否可以将第一个列表中的所有参数转换为第二个列表。到目前为止,我有这样的事情: template class conv{ public: t
我想了解可变参数模板的工作原理。在下面的示例中,我想将变量参数传递给类的构造函数并将其存储到一个元组中,以供稍后使用。 template class CompoundOrs { public:
我正在尝试创建一个可变参数模板类,其方法需要迭代模板参数并为每种类型调用不相关的模板函数。 这个想法是用特定的模板参数扩展这个模板类,以封装基本行为。 一般想法的一个简单示例是这个(糟糕的)Check
考虑这个最小的例子: template struct foo {}; template class Bar> struct converter { template conv
我有以下测试程序: #include template struct Dispatcher { template static inline void call1(bool a, bool
我有一个模板化函数包装器,我正在尝试将其更新为 C++11 语法(可变参数)。 我的问题是我陷入了“第 22 条军规”,其中 'Args...' 必须是最后一个模板参数,但同时不能在函数指针之后定义模
我正在尝试组合一个通用方法调用程序(用于 C++ OO/v8 桥),使用可变参数模板元编程构建参数列表,转换为 native 类型,最后执行附加方法,一旦传入参数列表为空(因此构建了传出): temp
我已经使用可变参数函数来包装 printf(或 vprintf)。 除了在 warning_printf 的第一个可变参数上出错外,以下代码有效。此外,直接放置字符串会更改 ASCII 字符,但不会修
在 stackoverflow 问题之后:“具有零参数和逗号的可变参数宏”,我尝试了: #define MAKE_TEMPLATE(...) template MAKE_TEMPLATE() str
为了我的理解,我正在尝试使用可变参数模板编写一个简单的记录器。它有效,但有一个问题。 void log() { std::cout void log(T t1,
我是一名优秀的程序员,十分优秀!