草庐IT

PrintDataAndAddress

全部标签

c++ - 在 B 类中声明为友元的 A 类成员模板函数无法访问 A 类的私有(private)成员(仅限 Clang)

请查看此代码段。我知道这没有多大意义,只是为了说明我遇到的问题:#includeusingnamespacestd;structtBar{templatevoidPrintDataAndAddress(constT&thing){cout(thing);}private://friendstructtFoo;//fixesthecompilationerrortemplatevoidPrintAddress(constT&thing){cout(consttFoo&);private:intmData=42;};structtWidget{intmData=666;};intmain(

c++ - 在 B 类中声明为友元的 A 类成员模板函数无法访问 A 类的私有(private)成员(仅限 Clang)

请查看此代码段。我知道这没有多大意义,只是为了说明我遇到的问题:#includeusingnamespacestd;structtBar{templatevoidPrintDataAndAddress(constT&thing){cout(thing);}private://friendstructtFoo;//fixesthecompilationerrortemplatevoidPrintAddress(constT&thing){cout(consttFoo&);private:intmData=42;};structtWidget{intmData=666;};intmain(