我有一个前向声明的类,我希望能够在无法访问定义的头文件中找出该类的成员函数的返回类型。我可以做这样的事情,同时只在我的标题中包含前向减速吗?下面是一个在头文件可以访问定义的情况下有效的示例,但我想避免在我的头文件中包含这些定义:
// 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
};
最佳答案
前向声明意味着您知道类(或类模板)存在,而不是它包含的内容。由此,显然不可能得到任何成员的信息,包括成员函数。
关于c++ - 是否可以使用 decltype 来确定前向声明模板类的成员函数的返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23584107/