OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

no type named ‘type’ in ‘class std::result_of<std::function<int>(int)>’

  • Thread starter Thread starter user23267295
  • Start date Start date
U

user23267295

Guest
I`m try to write a class for parse *.so, when compile, got error: no matching function for call to... error: no type named 'type' in 'class std::result_ofstd::result_of<std::function<int(it)>', the code as follow:

Code:
    template<typename T>
    std::function<T> get_function(const string& funcName) {
        auto it = m_map.find(funcName);
        if (it == m_map.end()) {
            auto addr = dlsym(m_libHandler, funcName.c_str());
            if (nullptr == addr) {
                return nullptr;
            }

            m_map.emplace(std::make_pair(funcName, addr));
            it = m_map.find(funcName);
        }

        return std::function<T>((T*)(it->second));
    }

592  template<typename T, typename... Args>
593    typename std::result_of<std::function<T>(Args...)>::type excecute_func(const string& funcName,             Args&&... args) {
594        auto f = get_function<T>(funcName);
595        if (nullptr == f) {
596            string s = "can not find this function" + funcName;
597            throw std::exception(s.c_str());
598        }
599
600        return std::ref(f(std::forward<Args>(args)...));
    }

int main() {
        int ret = doip_lib_client.excecute_func<int, int>("init_doip_client", 1);

}

error as follow:

Code:
cplusplus_prac.cpp: In function ‘int main()’:
cplusplus_prac.cpp:615:76: error: no matching function for call to ‘SoParser::excecute_func<int, int>(const char [17], int)’
  615 |         ret = doip_lib_client.excecute_func<int, int>("init_doip_client", 1);
      |                                                                            ^
cplusplus_prac.cpp:593:62: note: candidate: ‘template<class T, class ... Args> typename std::result_of<std::function<T>(Args ...)>::type SoParser::excecute_func(const string&, Args&& ...)’
  593 |     typename std::result_of<std::function<T>(Args...)>::type excecute_func(const string& funcName, Args&&... args) {
      |                                                              ^~~~~~~~~~~~~
cplusplus_prac.cpp:593:62: note:   template argument deduction/substitution failed:
cplusplus_prac.cpp: In substitution of ‘template<class T, class ... Args> typename std::result_of<std::function<T>(Args ...)>::type SoParser::excecute_func(const string&, Args&& ...) [with T = int; Args = {int}]’:
cplusplus_prac.cpp:615:76:   required from here
cplusplus_prac.cpp:593:62: error: no type named ‘type’ in ‘class std::result_of<std::function<int>(int)>’

any one could help, where is the problem

search on the internet, try to fix it, but not work
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
3
Total visitors
3
Top