Not able to understand why getting error
error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream’} and ‘MyStruct’) cout << st;
in the below code
#include <iostream>
using namespace std;
struct MyStruct
{
int a;
string b;
double c;
MyStruct(int a, string b, double c):a(a),b(b),c(c){}
ostream& operator<<(ostream& os)
{
os << "a " << a << " b" << b << " c" << c;
return os;
}
};
template <typename T, typename ... Args>
T create(Args&& ... Arg)
{
return T(Arg...);
}
int main() {
// your code goes here
MyStruct st = create<MyStruct>(5, "My Struct", 2.5);
cout << st;
return 0;
}
<<where you can dost << cout.