#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template <class T>
inline string to_string(const T& t) {
stringstream ss;
ss << t;
return ss.str();
}
class DataType {
public:
DataType(int);
DataType(string, int = 3);
const char *getData();
private:
string anyData;
};
DataType::DataType(int dt) {
anyData = to_string(dt);
}
DataType::DataType(string str, int dt) {
anyData = str;
anyData += to_string(dt);
}
const char *DataType::getData() {
return anyData.c_str();
}
int main(void) {
DataType data1 = 8; //1
DataType data2 = string("a"); //2
DataType data3 = DataType(string("b"), 6);
DataType data4 = DataType(5);
cout << data1.getData() << " " << data2.getData() << " " << data3.getData() << " " << data4.getData();
return 0;
}
Login in to like
Login in to comment