如果你有一个模板化的类或模板化的函数(或两者的组合),你如何绑定该函数,(保留模板类型参数)?
我在下面的帖子中给出了一些关于基本语法的帮助,用显式模板类型参数绑定到函数,但是在这个过程中失去了提供模板类型参数的能力.
是否有可能使其工作,以便仍然可以提供未来调用的模板类型参数?
清理过这段代码很多,但显然无法编译,因为我找不到正确的语法,(有没有办法做到这一点)?
删除了"向量"要求以简化此操作:
谢谢您的帮助!
#include <functional>
#include <vector>
#include <string>
/***************************************/
template <typename CommandTemplateType>
class Storage
{
public:
// No idea how to define this vector to allow Template Parameters
// static std::vector<std::function<void<ParameterTemplateType>
// (std::shared_ptr<ParameterTemplateType>)>> Functions;
// I really don't need the collection, a single member would kick start my research:
static std::function<void<ParameterTemplateType>(std::shared_ptr<ParameterTemplateType>)> Function;
template <typename ParameterTemplateType>
static void Execute(ParameterTemplateType parameter)
{
// Look up index, or loop through all..
// I am trying to invoke the bound …Run Code Online (Sandbox Code Playgroud) 不是从构造函数调用虚函数和纯虚函数的重复:
前一个问题涉及C++ 03,而不是C++ 11中新的构造函数委派行为,并且该问题没有通过使用委托来确保在执行纯虚拟实现之前正确构造来解决未定义行为的问题.
在C++ 11中,在构造期间在类的构造函数中调用Pure Virtual函数有什么危险,但是在通过构造函数委托"完全构造"类/对象之后?
显然,在C++ 11规范的某个地方存在这样的约束,
可以为正在构造的对象调用成员函数(包括虚拟成员函数,10.3).类似地,正在构造的对象可以是typeid运算符的操作数. - [C++工作草案]的12.6.2#13(http://www.open-std.org/jtc1/sc22/wg21/docs/ papers/2011/n3242.pdf)找不到已发布规范的"合理使用"版本.
一旦任何构造函数完成执行,C++ 11就会考虑构造一个对象.由于将允许多个构造函数执行,这意味着每个委托构造函数将在其自己类型的完全构造的对象上执行.派生类构造函数将在其基类中的所有委托完成后执行.- 维基百科说这是C++ 11的事情.
实际C++ 11参考未知.
以下示例在Visual Studio 2012 C++编译器的Nov CTP中编译和运行RUNS:
#include <string>
/**************************************/
class Base
{
public:
int sum;
virtual int Do() = 0;
void Initialize()
{
Do();
}
Base()
{
}
};
/**************************************/
// Optionally declare class as "final" to avoid
// issues with further sub-derivations.
class Derived final : public Base
{
public:
virtual int Do() override final
{ …Run Code Online (Sandbox Code Playgroud) 我目前正在使用Visual Studio 2012,Eclipse,CodeBlocks和MinGW来编写C++ 11代码.
题:
我注意到GCC中的功能,(延迟,=与立即,= =,扩展/分配等),以及微软的nmake让我想知道官方的"makefile"标准是什么.
背景:
困难,(*咳嗽),是我试图确保代码在每个环境中编译,以及尝试交叉编译到其他目标,(Linux/Ubuntu使用OpenGL API,Windows 7,8,使用DirectX,Android NDK).
我的核心问题之一是我使用的很多工具集并不真正"开放"支持跨平台的超棒.
Visual Studio 2012:没有*nix可运行的编译器.使用2012年11月C++ CTP编译器的错误版本支持C++ 11.
GCC 4.7.x/4.8x:仅限于MinGW32和MinGW64的粗略版本.
CMake:很难正确配置,但似乎创建特定于GNU,Microsoft等的makefile.有没有办法配置它来生成"标准"makefile?
AutoMake/AutoConf:似乎只生成GNU兼容的makefile
c++ ×3
c++11 ×3
callback ×1
constructor ×1
delegation ×1
makefile ×1
portability ×1
pure-virtual ×1
std-function ×1