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