久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將 const char* 作為模板參數(shù)傳遞

Passing const char* as template argument(將 const char* 作為模板參數(shù)傳遞)
本文介紹了將 const char* 作為模板參數(shù)傳遞的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

為什么你不能在這里傳遞文字字符串?我通過一個非常小的解決方法使它工作.

Why can't you pass literal strings in here? I made it work with a very slight workaround.

template<const char* ptr> struct lols {
    lols() : i(ptr) {}
    std::string i;
};
class file {
public:
    static const char arg[];
};
decltype(file::arg) file::arg = __FILE__;
// Getting the right type declaration for this was irritating, so I C++0xed it.

int main() {
    // lols<__FILE__> hi; 
    // Error: A template argument may not reference a non-external entity
    lols<file::arg> hi; // Perfectly legal
    std::cout << hi.i;
    std::cin.ignore();
    std::cin.get();
}

推薦答案

因為這不是一個有用的實用程序.由于它們不是模板參數(shù)的允許形式,因此目前不起作用.

Because this would not be a useful utility. Since they are not of the allowed form of a template argument, it currently does not work.

讓我們假設(shè)它們有效.因為對于所使用的相同值,它們不需要具有相同的地址,所以即使您的代碼中具有相同的字符串文字值,您也會獲得不同的實例化.

Let's assume they work. Because they are not required to have the same address for the same value used, you will get different instantiations even though you have the same string literal value in your code.

lols<"A"> n;

// might fail because a different object address is passed as argument!
lols<"A"> n1 = n;

您可以為您的文本編輯器編寫一個插件,用逗號分隔的字符文字列表替換字符串并返回.使用可變參數(shù)模板,您可以以某種方式解決"這個問題.

You could write a plugin for your text editor that replaces a string by a comma separated list of character literals and back. With variadic templates, you could "solve" that problem this way, in some way.

這篇關(guān)于將 const char* 作為模板參數(shù)傳遞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區(qū)別?)
Difference between const. pointer and reference?(常量之間的區(qū)別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內(nèi)容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態(tài)?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導(dǎo)致訪問沖突?)
主站蜘蛛池模板: 国产一区在线视频 | 久久男人 | 国产激情视频网址 | 国产亚洲www| 欧美日韩国产精品一区 | 中文字幕免费视频 | 一区二区视频在线 | 国产一二区视频 | 天堂av免费观看 | 精品二区 | 日韩精品一区二区三区中文在线 | 欧美成人精品激情在线观看 | 午夜免费网站 | 亚洲欧美日韩精品久久亚洲区 | 野狼在线社区2017入口 | 91免费在线视频 | 激情视频中文字幕 | 中文字幕免费视频 | 日韩一区二区在线视频 | 国产精品美女久久久久aⅴ国产馆 | 看片地址 | 精产国产伦理一二三区 | 男女羞羞视频网站 | 日韩影音| 成人三级av| 亚洲不卡在线视频 | 青春草在线 | 中文字幕日韩一区 | 亚洲草草视频 | 日韩欧美中文字幕在线观看 | 国产精品五月天 | 日本一区二区三区四区 | 国产精品明星裸体写真集 | 羞羞在线观看视频 | 精品一区二区三区免费毛片 | 在线播放精品视频 | 青娱乐国产 | 久国久产久精永久网页 | 激情av| av中文字幕在线 | 成人国产精品久久 |