0

suppose I have a class like this:

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;
};

I wonder why following code gets compiled and why the output is "1" ?

 namedType<float> nf(); // this is not right, but I do not know why !
 cout<<nf;
hadi sadeghi
  • 517
  • 4
  • 7

0 Answers0