Re: [問題] C++用marco debug的寫法
※ 引述《sudada (嘰咕嘰咕嘰咕)》之銘言:
: 所以請教有沒有比較好的寫法 謝謝
搞一個空的輸出就好了吧 ...
class Null {
public:
// 為了 std::endl
Null & operator <<( std::ostream & (*)( std::ostream & ) ) {
return *this;
}
// 其他的都來這裡
template< typename T >
Null & operator <<( const T & ) {
return *this;
}
};
#ifdef DEBUG
# define _DEBUG std::cerr
#else
extern Null null;
# define _DEBUG null
#endif
然後
_DEBUG << "const char *" << 1 << 1.5 << std::endl;
都可以丢給 null 或 cerr
注意 std 不能省 ... 誰知道 source 有沒有 using namespace
overhead 應該是不會太多
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 112.104.49.233
※ 編輯: legnaleurc 來自: 112.104.49.233 (04/06 00:12)
推
04/06 02:00, , 1F
04/06 02:00, 1F
→
04/06 02:21, , 2F
04/06 02:21, 2F
→
04/06 02:22, , 3F
04/06 02:22, 3F
討論串 (同標題文章)