nested function pointer

명관 송 21 Reputation points
2022-03-15T06:14:12.903+00:00

183172-image.png

Can I do the test function here?

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2022-03-15T07:23:25.287+00:00

    Hi, @명관 송
    What test needs is a function pointer (which with void* function as a parameter). cc is actually not called.

    snippet without error, output nothing:

    #include<iostream>  
    void cc(void (*pFunc)())  
    {  
     std::cout << "1" << std::endl;  
    }  
    void vv()  
    {  
     std::cout << "2" << std::endl;  
    }  
    void test(void (*pFunc)(void (*pFun2)()))  
    {  
      
    }  
    int main()  
    {  
     test(cc);  
    }  
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. RLWA32 51,361 Reputation points
    2022-03-15T13:34:50.38+00:00

    Consider the following which uses the function pointers to produce output -

    #include <iostream>
    
    void cc(void (*pFunc)())
    {
        std::cout << "1\n";
        pFunc();
    }
    
    void vv()
    {
        std::cout << "2\n";
    }
    
    void test(void (*pFunc)(void (*)()), void (*pFunc1)())
    {
        pFunc(pFunc1);
    }
    
    int main()
    {
        test(cc, vv);
        return 0;
    }
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.