簡體   English   中英

在gdb中打印boost boost強類型定義的類型

[英]Print boost strong typedef'ed type in gdb

我在代碼中使用了BOOST_STRONG_TYPEDEF來基於std::string分隔不同類型的標識符(例如,這樣我就可以擁有SERVER_IDFILE_ID ,並且當函數需要一個ID時不要意外地傳遞服務器的ID。文件)。

我現在正在調試我的代碼,並在遍歷一組此類型定義的對象時,打印當前元素將很有用。 不幸的是,boost的模板化性質使輸出非常難以閱讀:

(gdb)p服務器

$ 11 =(const mpn :: SER_ID&)@ 0x756660:{,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base>>> > = {,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base >> = {,std :: allocator>,boost :: equal_comparable2,std :: allocator>,boost :: detail :: empty_base> >> = {,std :: allocator>,boost :: detail :: empty_base >> = {> = {},},},},} ,},},t =“ B” ...}

是否可以通過某種方式將對象轉換為字符串(C ++允許使用static_cast )並將其正常打印?

有某種方法可以將對象轉換為字符串

是的:您需要為其定義漂亮的打印機。 文件資料 例子

事實證明, BOOST_STRONG_TYPEDEF包含基礎對象作為typedef的屬性t

(gdb) p server.t

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM