Here is my coding:
#include<iostream>
#include<string>
using std::endl;
using std::cin;
using std::cout;
using std::string;
using std::istream;
struct worker
{
worker()=default;
worker(istream &f);
int data;
};
int main()
{
worker a;
cout<<a.data<<endl;
system("Pause");
return 0;
}
worker::worker(istream&f)
{
read(f,*this);
}
istream&read(istream &f,worker&student)
{
f>>student.data
return f;
}
But when I debug,it warns me that I haven't initialized the element of a
. I know that I need to input the data through worker(istream &f)
, but I don't know how to invoke the constructor function to initialize a.data
.