2013-09-30 29 views
2
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 
+1

嘗試'debug(a,b,c);' – RedX

+0

不應該是g ++ -DDEBUG a.cpp -oa而不是g ++ -DEBUG a.cpp -oa – drescherjm

+0

您的命令行參數應該是-DDEBUG - - -D是「定義」。現在你正在定義「EBUG」。 – jwismar

回答

5

你可以簡單地嘗試使用: -

debug(a, b, c); 

你也必須更改命令行-DDEBUG -- the -D is "define"。目前您正在定義"EBUG"

+0

和-DDEBUG而不是定義EBUG,它不會打印任何內容(請參閱註釋) – doctorlove

+0

@doctorlove: - 是的,這是正確的。更新了! –