fork(1) download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. template <class T1>
  9. class TypeSize
  10. {
  11. public:
  12. TypeSize(T1 value)
  13. {
  14. this->value = value;
  15. }
  16. void DataTypeSize()
  17. {
  18. cout << "value = " << sizeof(value) << endl;
  19. }
  20. protected:
  21. T1 value;
  22. };
  23.  
  24. template <class T1>
  25. class TypeInfo : public TypeSize <T1>
  26. {
  27. public:
  28. TypeInfo(T1 value) : TypeSize<T1>(value)
  29. {
  30.  
  31. }
  32. void ShowTypeName()
  33. {
  34. cout << "Название типа " << typeid(TypeSize<T1>::value).name() << endl; // ошибка 'value' was not declared in this scope
  35. }
  36. };
  37.  
  38. int main()
  39.  
  40. {
  41. //setlocale(LC_ALL, "ru");
  42.  
  43. double a = 0;
  44. TypeInfo<double> c(a);
  45.  
  46. c.DataTypeSize();
  47. c.ShowTypeName();
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0s 4476KB
stdin
Standard input is empty
stdout
value =  8
Название типа d