簡體   English   中英

我如何獲得函數中參數的名稱

[英]How would I get the name of the parameters in a function

我有一個功能

void print(stack<T>& One, stack<T>& Two, stack<T>& Three);

而且我想輸出參數名稱(即cout <<“ One”)

我將如何去做?

您不能這樣做,因為編譯器甚至可能不將參數名稱保留在生成的目標文件中。 可以刪除符號,或者可以完全優化參數。

cout << ##One; //Outputs "One"
cout << ##Two; //Outputs "Two"
cout << ##Three; //Outputs "Three"

請參閱http://www.cplusplus.com/doc/tutorial/preprocessor/並搜索##。

宏##將以下符號替換為文本。 因此## One在預處理程序步驟中變為“一個”。

暫無
暫無

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

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