How to use weak function in C++
问题 I am trying to use weak function in a class in C++. Below is what I wrote: #include <stdio.h> #include <iostream> class A { public: void func(int argc, char *argv[]) __attribute__((weak)); }; // optional definition: #if 0 void A::func(int argc, char *argv[]) { printf("In func()\n"); for(int aa = 0; aa < argc; aa++){ printf("arg %d = %s \n", aa, argv[aa]); } } #endif int main(int argc, char *argv[]) { A a1; if (a1.func){ a1.func(argc, argv); } else { printf("func() not available\n"); } return