簡體   English   中英

朋友聲明和顯式模板實例化聲明

[英]Friend declaration and explicit template instantiation declaration

假設我有一個功能模板

template <typename T>
void f(T) {}

然后,我們可以有一個朋友聲明

friend void f<int>(int);

和一個顯式的模板實例化聲明

extern template void f<int>(int);

這兩個聲明是以某種方式關聯還是完全獨立? 如果相關,它們如何相互影響?

friend聲明不與任何事物“交互”,除了聲明為朋友的函數定義之外,該函數允許訪問包含該聲明的類的私有成員。

因此,沒有,有沒有過大的相互作用friend聲明和extern template聲明,雖然他們都指向相同的功能(在這個意義上說,它們是相關的,但我相信你意識到了這一點,當你寫的問題)。

暫無
暫無

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

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