How to Bypass a Standard C++ Function While Maintaining Its Functionality

前端 未结 7 856
迷失自我
迷失自我 2021-01-24 03:03

I am looking for a way to be able to redefine a set of POSIX functions but then end the redefinition with a call to the original function. The idea is that I am trying to create

相关标签:
7条回答
  • 2021-01-24 03:33

    Here is how you would you change MY_string.h

    #include <cstring>
    
    namespace my_functions{
        char *strcpy(char *s1, const char *s2)
        {
    #if defined(PROFILE_PASS_THROUGH)
            printf("strcpy is not allowed in this profile\n");
            return std::strcpy(s1, s2);
    #elif defined(PROFILE_ERROR)
            static_assert(0, "strcpy is not allowed in this profile\n");
            return 0;
    #else
            return std::strcpy(s1, s2);
    #endif
         }
    
    }
    using namespace my_functions;
    

    For this to work you cannot include or have using namespace std;

    0 讨论(0)
提交回复
热议问题