using namespace std;
#ifdef DEBUG
#define debug(args...) {dbg,args; cerr<<endl;}
#else
#define debug(args...) // Just strip off all debug tokens
#endif
struct debugger
{
template<typename T> debugger& operator , (const T& v)
{
cerr<<v<<" ";
return *this;
}
} dbg;
int main(){
int a=1,b=2,c=3;
debugger(a,b,c);
}
我發現這個調試宏,我試圖用這個,但是這是行不通的。我收到以下錯誤:如何使用此調試宏?
ubuntu:~ g++ -DEBUG a.cpp -o a
a.cpp: In function ‘int main()’:
a.cpp:81:16: error: no matching function for call to ‘debugger::debugger(int&, int&, int&)’
a.cpp:81:16: note: candidates are:
a.cpp:62:8: note: debugger::debugger()
a.cpp:62:8: note: candidate expects 0 arguments, 3 provided
a.cpp:62:8: note: debugger::debugger(const debugger&)
a.cpp:62:8: note: candidate expects 1 argument, 3 provided
嘗試'debug(a,b,c);' – RedX
不應該是g ++ -DDEBUG a.cpp -oa而不是g ++ -DEBUG a.cpp -oa – drescherjm
您的命令行參數應該是-DDEBUG - - -D是「定義」。現在你正在定義「EBUG」。 – jwismar