Monday, February 12, 2018

Template class generate errors in C++

This program is not compiling. What's the problem?


#include
#include
using namespace std;
templateclass Data{
string header;
T data;
public:
Data(string h, T d){header = h, data = d;}
void WriteData()
{
cout< }
};
int main(int argc, _TCHAR* argv[])
{
Data idata("Roll", 100);
Datasdata("Name","Jakir");
idata.WriteData();
sdata.WriteData();
return 0;
}

Showing the following errors.



error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<>(std::basic_ostream<_Elem,_Traits> &,const char *)'
with
[
_Elem=char,
_Traits=std::char_traits
]


while trying to match the argument list '(std::ostream, std::string)'
.....\maptest\mapt\mapt\mapt.cpp(16) : while compiling class template member function 'void Data::WriteData(void)'
with
[
T=int
]


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...