繁体   English   中英

是否可以使用decltype来确定前向声明的模板类的成员函数的返回类型?

[英]Is it possible to use decltype to figure out the return type of a member function of a forward declared template class?

我有一个我已经声明的类,我希望能够在头文件中找出该类的成员函数的返回类型,该文件无法访问该定义。 我可以做这样的事情而只包括我的标题中的前向变换吗? 如果标题可以访问定义,则可以使用一个示例,但我希望避免在头文件中包含这些定义:

// file name Matrix.hpp
#include<utility>
#include "array.hpp" // I would like to remove this include

template<typename T, unsigned int N>
class Array;

using MatrixD = Array<double, 2>; 
using return_type = decltype(std::decval<MatrixD>().operator()("i,j"));

class Array_User{
public:
    virtual return_type Array_op(const std::string);
    ... Rest of class 
};

不可以。类型必须是完整的,并且在那一刻就已知道。

前向声明意味着您知道类(或类模板) 存在 ,而不是它包含的内容 因此,显然无法获得有关任何成员的信息,包括成员函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM