Re: [問題] C++用marco debug的寫法
有點離題 只是有點好奇
Null & operator <<( std::ostream & (*)( std::ostream & ) )
這個為什麼不能寫成
template <typename T> Null & operator <<( T & (*)( T & ) )
如果改這樣就會不能編繹 很奇怪
※ 引述《legnaleurc (CA)》之銘言:
: ※ 引述《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: 1.160.33.110
推
04/06 23:48, , 1F
04/06 23:48, 1F
→
04/06 23:48, , 2F
04/06 23:48, 2F
推
04/07 02:43, , 3F
04/07 02:43, 3F
→
04/07 02:44, , 4F
04/07 02:44, 4F
→
04/07 02:45, , 5F
04/07 02:45, 5F
→
04/07 19:24, , 6F
04/07 19:24, 6F
討論串 (同標題文章)