Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;模板确定函数返回类型_C++_Templates - Fatal编程技术网

C++ C++;模板确定函数返回类型

C++ C++;模板确定函数返回类型,c++,templates,C++,Templates,如何确定成员泛型函数的返回类型 template<class E> struct result<E> { // E has member function data(), I need to know its return type typedef typename &E::data type; }; 模板 结构结果{ //E有成员函数data(),我需要知道它的返回类型 typedef typename&

如何确定成员泛型函数的返回类型

    template<class E>
    struct result<E> {
        // E has member function data(), I need to know its return type
        typedef typename &E::data type;
    };
模板
结构结果{
//E有成员函数data(),我需要知道它的返回类型
typedef typename&E::数据类型;
};
有没有可能用一般的方法来做呢? 我知道有
boost::result\u的

boost实现将非常好。

GCC的非标准操作符也可以做到这一点。

如果您使用的是VS2010或GCC 4.3,至少可以使用C++0x new关键字。

如果没有重载函数,这似乎是可行的。您知道如何处理有两个函数(一个具有常量限定符)的情况吗?在使用之前,您需要将函数类型转换为常量或非常量类型。boost::bind也有同样的问题。@brad谢谢。在类型转换之前我不需要知道返回类型吗?你能举个例子吗?这里用boost::bind描述了这个问题,以及如何处理它。也许,你根本不需要那种魔力。尝试使用
E::value\u type*
E::pointer
。如果它有
data()
,它很可能是一个容器,并提供公共的typedefs。@Johannes谢谢。实际上,他正在尝试编写包装器,以透明地与ublas和其他东西一起工作。不幸的是,ublas data()接口有点不标准(array_类型),所以我单独对它进行了专门化。