Hello everybody, will be grateful is somebody can help!
I get errors C2100 (illegal indirection) and C2088 ("<<": illegal for class) while trying to use the myPrint function (irrespectively of whether the set for printing contains pointers or not):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
template <class T = std::string>
void myPrint(const std::set<T>& mySet)
{
std::cout << "Size of vector is " << mySet.size() << ", Pointers: ";
bool pp = false; std::string str = "no";
if (std::is_pointer<T>::value) { pp = true; str = "yes"; }
std::cout << pp << "\n[";
std::set<T>::const_iterator i;
for (i = mySet.begin(); i != mySet.end(); ++i)
{
if (pp) { std::cout << *(*i) << ","; }
else { std::cout << *i << ","; }
}
std::cout << "]\n";
}
The errors point to the line "if (pp) { std::cout << *(*i) << ","; }", but I cannot figure out what's wrong with it... Anybody knows how to solve this problem?
This is the default type (i.e. if I will call myPrint<>(x) then x should be set of strings), but generally T can be any: double*, int, char* etc. (e.g. for myPrint<double>(x) the set x should obviously consist from double).