问题标签 [template-function]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 为什么 ADL 找不到函数模板?
C++ 规范的哪一部分限制依赖于参数的查找在关联的命名空间集中查找函数模板?换句话说,为什么main
下面的最后一个调用无法编译?
c++ - C++ 模板函数是线程安全的吗?
谷歌搜索没有找到任何东西。它们是在使用点创建的,还是在实例之间共享通用部分?
(模板类也一样?)
c++ - templated function seemingly creates temporary container
In an application I am maintainig I came across a persistence class that had 6 functions that all did the same thing except for the type of item that was being persisted. These items are all of the same base class - a candidate for a template function.
However once I had converted them it would seem that when the function is being stepped into to the container that is being written to is always empty (a temporary copy being created?) despite the fact it should have several items in it. To be sure, inspecting the container in the debugger it has zero items it. Also the writing function triggers an event that notifies the client of an change in status, but when that thread goes to extract the item from the deque it is always now empty.
The base class is called CItem and all other items are specialities of that Item (CErrorItem
, etc). They all are persisted in a deque (std::deque<std::tr1::shared_ptr<CItem>> m_items;
), and to disk. The items are written to disk correctly. Once processed correctly the items are removed from both the deque and disk.
Items are added with the code m_persistence.Add<CErrorItem>(errorItem);
All data for items are stored in simple structs (eg ErrorItemInfo
), and the Items take these simple data stores in their constructor. It is this struct that is denoted by the U
in the below code. The T
is the derived CItem
.
The function that adds the items is the following:
The simplest solution is to revert the code back to specific functions, and probably I will do that, but I would like to understand why this is occuring so I can avoid it in the future.
c++ - 不同文件中的模板函数和类使用
我想在一个文件中定义一个模板函数并在多个文件中使用。这是否与常规函数原型的工作方式相同?所以我可以定义一次,然后将原型包含在其他文件中?我对类有同样的问题,我是否必须在每个头文件中包含模板类的完整定义,就像我对类一样?如果我在单独的文件中定义了两次模板函数,或者这只是未经检查,会导致错误吗?
还有一个问题,模板函数原型的格式是什么?
c++ - 使用点后模板函数的特化会破坏编译
考虑下一个例子:
编译失败并出现以下错误消息:
标准中的哪一段解释了这个错误?
PS:我知道如果我将函数定义移到 main 前面会使错误消失。
c++ - eMbedded Visual C++ 4.0 for Windows CE 中的模板函数
eMbedded Visual C++ 4.0 (SP4) 是否支持模板函数?当我尝试编译可在 Visual C++ 6.0 中正常运行的代码时出现错误。
这是我的模板函数,它可以编译:
模板函数用法:
编译错误:
我需要更改一些编译器开关吗?我如何让它编译?
c++ - C++:如何在模板函数中使用类型来分支?
我对模板不是很熟练。如何编写一个名为 get 的模板函数,该函数根据模板类型选择从中获取的数组?请参见下面的示例:
c++ - 如何在 C++ 的模板函数中传递普通参数和模板参数?
我在名为 myNamespace 的命名空间中有一个模板函数(如下):
但是,每当我调用此函数时,我都会收到以下错误:
我已经尝试了所有组合,但没有运气,请帮助我!!!
c++ - 带有取自迭代器的指针参数的 C++ 模板函数给出错误
如果标题描述性不够,我很抱歉,我不知道这有什么问题:
当我从以下成员函数中调用上述函数时:
我总是得到:
policy.hpp:237: error: no matching function for call to 'findPolicy(boost::ptr_vector<Greedy<guState>, boost::heap_clone_allocator, std::allocator<void*> >&, State*&)
c++ - 具有模板化参数的 C++ 函数模板
我正在尝试编写一个函数,它可以将任何标准容器(列表、堆栈、向量等)作为它的参数。我也想知道容器内的类型。这是我尝试过的。
此函数中的 once 类型container_type
始终是_Container_base_aux_alloc_empty
which(我认为)是标准容器的基类。
这里发生了什么?
我如何让这个函数返回正确的类型?