草庐IT

扣除额

全部标签

c++ - 返回类型自动扣除的好友函数模板无法访问私有(private)成员

对不起,这个问题的标题太复杂了;我试图描述我为这个问题构建的最小SSCCE。我有以下代码:#includenamespacefizz{templateclassbar{public:templatefriendautofoo(constbar&);private:inti=123;};templateautofoo(constbar&b){returnb.i;}}intmain(){std::cout(fizz::bar{});}此代码compileswithGCC5.2和doesn'twithClang3.7:main.cpp:19:18:error:'i'isaprivatemem

c++ - 自动返回类型扣除是否适用于 main?

我能否在C++1y(C++14)中对main函数执行以下操作:automain(){//...}即使我们不需要使用显式的return0;,返回类型是否会自动为int? 最佳答案 不,不允许。C++14标准草案N3690第7.1.6.4/10段规定:Ifafunctionwithadeclaredreturntypethatusesaplaceholdertypehasnoreturnstatements,thereturntypeisdeducedasthoughfromareturnstatementwithnooperandat

c++ - 自动返回类型扣除是否适用于 main?

我能否在C++1y(C++14)中对main函数执行以下操作:automain(){//...}即使我们不需要使用显式的return0;,返回类型是否会自动为int? 最佳答案 不,不允许。C++14标准草案N3690第7.1.6.4/10段规定:Ifafunctionwithadeclaredreturntypethatusesaplaceholdertypehasnoreturnstatements,thereturntypeisdeducedasthoughfromareturnstatementwithnooperandat