C++ 为什么要编译这个私有模板函数-&燃气轮机;编译器Bug VS 2009
这在VS 2009中编译时没有问题?我笨吗? GCC发出警告,模板是私有的。。。。? 我错过了什么C++ 为什么要编译这个私有模板函数-&燃气轮机;编译器Bug VS 2009,c++,templates,compiler-bug,C++,Templates,Compiler Bug,这在VS 2009中编译时没有问题?我笨吗? GCC发出警告,模板是私有的。。。。? 我错过了什么 #include <iostream> using namespace std; class A { private: template<typename T> A& operator<<(const T & v) { cout << v << endl; ret
#include <iostream>
using namespace std;
class A
{
private:
template<typename T>
A& operator<<(const T & v)
{
cout << v << endl;
return *this;
}
};
int main()
{
A a;
a << 4;
system("pause");
}
#包括
使用名称空间std;
甲级
{
私人:
模板
A&operator此代码不应编译-这是VS中的错误(或愚蠢的扩展)。GCC也应拒绝它。运算符在其使用的范围内不可访问
科莫正确对待这一点:
"ComeauTest.c", line 28: error: function "A::operator<<(const T &) [with T=int]"
(declared at line 14) is inaccessible
a << 4;
“ComeauTest.c”,第28行:错误:函数“A::operator不,你不笨-它是坏代码,应该被拒绝。Comeau编译器()确实正确地拒绝了它。微软承认了这个错误,并声称它将在下一个主要版本的编译器中修复(我读作VC11/VS-whatever-is-after-2010-可能不是VC10/VS2010的服务包):
从注释来看,修复程序似乎已经对内部编译器版本进行了修改