我處于一個奇怪的困境,我無法控制正在使用的庫。為了進一步解釋,我使用了兩個庫 liba 和 libb。Libb 需要 liba 才能運行。現在問題來了,liba 不僅包含該類,而且還定義了它,而 libb 會查找該定義。當一切正常時,一切都很好,但如果不正常,我就不走運了。
庫檔案
class myclassA{
// some code here
};
myclassA varA(0,2,1,3); //The parameters need to be changed
當然,我可以在本地編輯 liba.h,但這意味著如果我的代碼要使用另一臺計算機編譯,則修改將不會持續存在,并且必須每次為每臺計算機編輯其 liba.h。
那么有什么方法可以強制重新定義 varA 而不會在編譯時拋出錯誤?
我的代碼看起來像這樣:
#include <liba.h>
myvlassA varA(0,1,2,3); // Of course this throws a multiple definition error
#include <libb.h>
有沒有辦法基本上用我的新變數定義洗掉舊變數定義?
uj5u.com熱心網友回復:
#include <liba.h>
myclassA myVarA(0,1,2,3);
#define varA myVarA
#include <libb.h>
uj5u.com熱心網友回復:
有一次我不得不做類似的事情,也許你想要類似的東西
#include <stdio.h>
/* gcc lmao.c -Wl,--wrap=puts -o lmao */
int __real_puts(const char*);
int __wrap_puts(const char*a) {
__real_puts("u just got hacked\n");
__real_puts(a);
}
int main() {
/* gcc uses puts for this cool right*/
printf("main, calling thing\n");
}
這將列印
u just got hacked
main, calling thing
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/334419.html
上一篇:將zsh提示更改為僅兩個檔案夾
下一篇:Applescript谷歌翻譯
