简体   繁体   中英

No matching function for call c++

I am getting this error.

error: no matching function for call to 'namespaceA::ClassA<namespaceB::someFunc<short int, 3u>, namespaceB::someFunc<float, 3u> >::funcFromA(int&, void (namespaceB::classB<namespaceB::someFunc<short int, 3u>, namespaceB::someFunc<float, 3u> >::*)(void*), int&)'

note: candidates are: void namespaceA::ClassA<TYPE_A, TYPE_B>::funcFromA(int, void (namespaceA::ClassA<TYPE_A, TYPE_B>::*)(void*), int) [with TYPE_A = namespaceB::someFunc<short int, 3u>, TYPE_B = namespaceB::someFunc<float, 3u>]

Classes are something like this

ClassA.h

template<typename TYPE_A, typename TYPE_B>
class ClassA {

typedef void (ClassA::*someTypeDef)(void*);

void funcFromA(int A, namespaceA::ClassA<TYPE_A, TYPE_B>::
                  someTypeDef takeFunc, int B);

}

ClassA.cxx

void namespaceA::ClassA::funcFromA(int A, 
          namespaceA::ClassA::someTypeDef takeFunc, int B) {
    // Do something with taken function
}

ClassB.h

template<typename TYPE_A, typename TYPE_B>
class classB {
void classB<TYPE_A, TYPE_B>::CallThisFunc(void *someParm);
    // Do Something
}

ClassB.cxx

template<typename TYPE_A, typename TYPE_B>
void classB<TYPE_A, TYPE_B>::CallThisFunc(void *someParm){
    // Do something
}

template<typename TYPE_A, typename TYPE_B>
void classB<TYPE_A, TYPE_B>::MainFunc() {
    int A = 1;
    int B = 1;
    ClassA->funcFromA(A, &classB::CallThisFunc, B); // <--- Error
}

I attempted to fix the error, but I was unsuccessful and it is killing me. How do I fix this problem?

Edit : The basic idea I am trying to accomplish is there are two classes, and I am trying to call ClassA function inside ClassB, and ClassB is templated and one of the parameter in ClassA method from ClassB is typedef.

The function ClassA<A, B>::funcFromA() takes a member function of ClassA<A, B> as parameter. You try to pass it a member function of ClassB<A, B> as argument, though. Since ClassA<A, B> and ClassB<A, B> are unrelated, this clearly won't work.

BTW, the redundant qualification of ClassB<A, B>::CallThisFunc doesn't make your code more readable and I think it is actually illegal although some compilers accept it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM