I am new to c++ templates. I am having trouble converting a templated member object to std::string. My code below fails to print the character 'c' (on my machine it prints 'R' instead) and I can't find a way to make it work. Is there a way to do this when using char as type T?
#include <iostream>
#include <string>
template<class T>
class A {
public:
T t;
A(T t1):t{t1}{};
std::string toString(){
return "" + static_cast<char>(t);
};
};
using namespace std;
int main()
{
A<char> a{'c'};
cout << a.toString() <<"\n";
return 0;
}