[問題] c++中的sealed物件

看板C_and_CPP (C/C++)作者 (raison detre)時間14年前 (2011/10/25 16:31), 編輯推噓1(107)
留言8則, 5人參與, 最新討論串1/1
請問一下各位 網路上有一些文章有教各位如何實做sealed物件 但是我照他們的方法實做之後卻無法編譯 請各位幫我指點一下問題 謝謝 以下是我的程式碼 template<typename T> class Sealed { protected: Sealed(){} }; template<typename T> class SealedSingleton : private virtual Sealed<T> { private: friend typename T; public: SealedSingleton(){} }; 然後錯誤訊息是 ../SealedSingleton.h:17: error: expected nested-name-specifier before 'T' ../SealedSingleton.h:17: error: 'T' is neither function nor member function; cannot be declared friend 我使用的編譯器是g++ 4.2.4 作業系統是AIX 5.2 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.220.71.34

10/25 16:44, , 1F
喔…原來是IBM的UNIX作業系統 ( ̄ー ̄;)
10/25 16:44, 1F

10/25 16:45, , 2F
你要不要換新一點的compiler...
10/25 16:45, 2F

10/25 16:48, , 3F
我是看不懂不過VC++ 2010 Express可以編過XD
10/25 16:48, 3F

10/25 17:08, , 4F
friend class T; 這樣呢? (不確定行就是了)
10/25 17:08, 4F

10/25 17:22, , 5F
也是不行= =a
10/25 17:22, 5F

10/25 17:24, , 6F
更新編譯器的版本(或是 升級系統)
10/25 17:24, 6F

10/25 17:28, , 7F
把所有的typename都改成class看看
10/25 17:28, 7F

10/25 17:28, , 8F
有些compiler好像不支援friend typename
10/25 17:28, 8F
文章代碼(AID): #1EfdFd8V (C_and_CPP)
文章代碼(AID): #1EfdFd8V (C_and_CPP)