Which will print the following program:
#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;
}
Explanation
Errors in lines 1 and 2 are not present in accordance with 12.3.1 on the page. 193 of the International Standard ISO/IEC 14882.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes