fork download
  1. // process_mix_of_items.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <string>
  5. #include <iostream>
  6.  
  7. //#include "holdCommandWindow.h"
  8.  
  9. class Personal_details {
  10.  
  11. public:
  12.  
  13. virtual void showdata(int i) {}
  14.  
  15. };
  16.  
  17. class Phone_extension : Personal_details {
  18.  
  19. public:
  20.  
  21. unsigned int areaCode;
  22.  
  23. unsigned long sevenDigitNumber;
  24.  
  25. Phone_extension(unsigned int aCode, unsigned long sDNumber) {
  26.  
  27. areaCode = aCode;
  28. sevenDigitNumber = sDNumber;
  29.  
  30. }
  31.  
  32. void showdata(int i){
  33.  
  34. std::cout << "Element index number " << i << " is a Phone extension (" << areaCode << ") " << sevenDigitNumber << "\n";
  35.  
  36. }
  37.  
  38. };
  39.  
  40. class Age : Personal_details {
  41.  
  42. public:
  43.  
  44. unsigned int ageYears;
  45.  
  46. Age(unsigned int aYears) {
  47.  
  48. ageYears = aYears;
  49.  
  50. }
  51.  
  52. void showdata(int i){
  53.  
  54. std::cout << "Element index number " << i << " is a Age " << ageYears << "\n";
  55.  
  56. }
  57.  
  58. };
  59.  
  60. class House_number : Personal_details {
  61.  
  62. public:
  63.  
  64. unsigned long houseNumber;
  65.  
  66. House_number(unsigned long hNumber) {
  67.  
  68. houseNumber = hNumber;
  69.  
  70. }
  71.  
  72. void showdata(int i){
  73.  
  74. std::cout << "Element index number " << i << " is a House number " << houseNumber << "\n";
  75.  
  76. }
  77.  
  78. };
  79. /*
  80. void showData(void *data[], int nData)
  81. {
  82.   std::cout << "\n";
  83.  
  84.   for ( int i=0; i < nData; ++i ) {
  85.  
  86.   id_kind id = *(reinterpret_cast<const id_kind*>(data[i]));
  87.  
  88.   std::cout << "Element index number " << i << " is a ";
  89.  
  90.   switch ( id ) {
  91.  
  92.   case id_phone_extension:
  93.  
  94.   const phone_extension *pPhone;
  95.  
  96.   pPhone = reinterpret_cast<const phone_extension*>(data[i]);
  97.  
  98.   std::cout << "Phone extension (" << pPhone->areaCode << ") " << pPhone->sevenDigitNumber << "\n";
  99.  
  100.   break;
  101.  
  102.   case id_age:
  103.  
  104.   const age *pAge;
  105.  
  106.   pAge = reinterpret_cast<const age*>(data[i]);
  107.  
  108.   std::cout << "Age " << pAge->ageYears << "\n";
  109.  
  110.   break;
  111.  
  112.   case id_house_number:
  113.  
  114.   const house_number *pHouse;
  115.  
  116.   pHouse = reinterpret_cast<const house_number*>(data[i]);
  117.  
  118.   std::cout << "House number " << pHouse->houseNumber << "\n";
  119.  
  120.   break;
  121.   }
  122.   }
  123. }
  124. */
  125.  
  126. int main()
  127. {
  128.  
  129. int i;
  130.  
  131. Personal_details pd;
  132.  
  133. pd = new Phone_extension(313, 4567892);
  134. // pd[1] = new Phone_extension(800, 3334455);
  135. //pd[2] = new Age( 39);
  136. // pd[3] = new Age(21);
  137. // pd[4] = new Age(44842);
  138.  
  139. // for(i=0;i<5;i++)
  140. // {
  141.  
  142. pd->showData(1);
  143.  
  144. // }
  145.  
  146. // return holdCommandWindow();
  147. }
  148.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:133: error: no match for ‘operator=’ in ‘pd = (((Phone_extension*)operator new(12u)), (<statement>, <anonymous>))’
prog.cpp:9: note: candidates are: Personal_details& Personal_details::operator=(const Personal_details&)
prog.cpp:142: error: base operand of ‘->’ has non-pointer type ‘Personal_details’
prog.cpp:129: warning: unused variable ‘i’
stdout
Standard output is empty