發表文章

目前顯示的是 9月 9, 2018的文章

Why can't forward declared friend class be referred in the class?

圖片
Clash Royale CLAN TAG #URR8PPP up vote 23 down vote favorite 4 The following code doesn't compile: struct X friend class Y; Y* ptr; ; The cppreference describes the situation as ... If the name of the class that is used in the friend declaration is not yet declared, it is forward declared on the spot. If the "spot" means where the friend relationship is declared, then it should be fine to declare the member Y* ptr . Why doesn't it compile? Where in the standard prohibits this? c++ friend share | improve this question asked Aug 27 at 18:12 Kan Li 3,278 3 31 76 3 @edtheprogrammerguy MSVC being able to compile something isn't the best of tests. both Clang and GCC fail to compile. – NathanOliver Aug 27 at 18:21 1 Please provide the specific compiler errors that you are seeing along with what compiler and version you are using. – Richard Chambers Aug 27 at 18:23 Ahh, that's not wh