簡體   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