templates相关内容
在 的主页( C ++ 11 FAQ ): struct X {int foo(int); }; std :: function F; f =& X :: foo; //指向成员的指针 X x; int v = f(& x,5); //调用X :: foo()for x with 5 它是如何工作的?如何 std ::
..
我有一个模板类,我需要访问模板参数的受保护成员函数,如下所示: class Foo { protected: void foo(){} }; template class Bar { public: static void bar(T& self){self.foo();} }; ... Foo f; Bar
..
考虑以下metafunction的一个完整的pow(它只是一个例子): class Meta { template static constexpr T ipow(T x) { return(N> 0)? (x * ipow
..
我希望标题有意义。 很好,一个例子可能会更清楚。 对我来说是:动态downcasting在运行时在以下一些情况(写在评论中)返回0。我想知道如果它是一个正确的行为(使用C ++ 11),也为什么,我该怎么做,使其工作。显然,Templated和A :: A_templated被视为不同的类,尽管使用别名“using”定义为相同。对于简单的typedef别名,不会出现问题。 模板
..
我知道C ++模板函数的定义必须放在头文件中。然而,为了提高(潜在)大库的可读性和结构的原因,我将声明从实现分离为“mock”头(其中 #include 实施文件,非常类似于文件的此结构)。 请注意,我知道在编译时必须包含模板函数的实现。 简而言之,当我将非模板函数声明添加到实现文件时,我有一个“多重定义”错误。详细说明如下。 当“mock”标题+实现文件对只包含模板函数的声明/ ,一
..
GCC似乎不赞成使用本地类实例化模板: template
..
看一下这段代码: template :: Iterator> BinaryTree :: GetBeginning()const { return new BinaryTreeIterator(this,BinaryTreeIterator :: Posi
..
// File:InitFirst.h #pragma once template struct InitFirst { static float s_dividedByThree; }; template float InitFirst :: s_dividedByThree = val / 3.0;
..
我最近在一个小项目上工作,我无法弄清楚一些东西。 我得到一个.h文件,包含类,使用typename模板。在该类中有一个私有类。 模板
..
a.h 模板 class B:public A { public: int f(); } template int B :: f() { int
..
根据 http://en.cppreference.com/w/ cpp / utility / functional / function / function ,初始化器的类型,即形式(5)中的 F 应该满足CopyConstructible的要求。我不太明白这一点。为什么 F 不能只是MoveConstructible? 解决方案 std :: function在内部使用类型擦除,因
..
编写模板函数,我声明: template
..
来自Herb Sutter的 GotW#6 对于非内置返回类型,返回值通常应为const。 ... 注意:Lakos(第618页)反对返回const值 ,并注意到它对于builtins来说是多余的 例如,返回“const int”),他注意到 会干扰模板实例化。 不同意在通过Lakos返回一个非构建类型的对象时是返回一个常量值还是非常量值,他通常同意返回一个内置类型的常量值
..
如何修改以下代码以允许模板函数 ask_runUI()使用 s_EOF 而不使 s_EOF public? #include #include #include #include class AskBase { protected: std :: string m_prompt; std
..
给定: 模板
..
当 T 是 double(float)const 当我尝试使用 function 。 未定义模板的隐式实例化'std :: function' 但是当 T 是 double(float)。我试图使用 std :: remove_cv :: type 删除这个 const 工作。是的,我有#include
..
可能重复: 我最近一直在用C ++。 目前我想编程的东西我确定以前至少做过一次:一个简单的LinkedList类。 代码完成,但我不知何故没有编译它。我一直在谷歌搜索,它似乎我链接的目标文件错误。这是我的代码基本上看起来像: test.cpp #include“linkedlist.h” int main() { LinkedList列表; //
..
我习惯看到函数指针的语法。 int(* pointer_name)(float,char *) ; void call_function(void(*)(int),int); 在一些C ++ 03函数库中,我看到类型使用这种方式: abc :: function F; 在C ++ 11的std ::
..
以下程序在使用GCC 4.7和clang 3.2编译时会生成“1”作为输出。 #include struct foo { template foo(T){ static_assert(not std :: is_same(),“no ints please”); } }; #include
..
所以我对如何工作感到困惑。给定: 模板 int foo(T t){t.foo(); } 看起来这个调用应该失败: decltype(foo(int {13}))fail = 42; cout
..