學習C++的時候讀到這樣的代碼
template<typename T>
class SharedPointer;
template<typename T>
auto swap(SharedPointer<T>& lhs, SharedPointer<T>& rhs)
{
using std::swap;
swap(lhs.ptr, rhs.ptr);
swap(lhs.ref_count, rhs.ref_count);
swap(lhs.deleter, rhs.deleter);
}
如果SharedPointer是普通類,那么前向宣告之后定義之前,肯定不能使用它的成員,只能使用它的指標或參考。但為什么類模板前置宣告后,定義之前,就能使用它的成員呢?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/12638.html
標籤:C++ 語言
上一篇:初學者,很多網站是英文,看不懂怎么辦,求各位傳授經驗
下一篇:C++怎么創建介面啊?
