假设我有一个这样的课程:
template <typename T>
class namedType {
public:
explicit namedType(const char* name, const T& ty):name(name), ty(ty){};
explicit namedType(const string &name, T ty) : name(name), ty(ty) {}
friend ostream&operator<<(ostream& ostr, namedType& nm){
cout<<nm.name<<" , "<<nm.ty<<endl;
}
private:
string name;
T ty;
};
我想知道为什么下面的代码被编译,为什么输出为“ 1”?
namedType<float> nf(); // this is not right, but I do not know why !
cout<<nf;