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

StackOverflow https://stackoverflow.com/questions/23584107

  •  19-07-2023
  •  | 
  •  

문제

I have a class which I have forward declared and I would like to be able to figure out the return type of a member function of that class in a header file which doesn't have access to the definition. Can I do something like this while only including forward declerations in my header? An example that works if the header has access to the definition is below, but I would like to avoid including the definitions in my header files:

// 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 
};
도움이 되었습니까?

해결책

Forward declared means that you know that the class (or class template) exists, not what it contains. From this, it's obviously impossible to get information about any members, including member functions.

다른 팁

No. The type must be complete and known at that moment.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top