0

So I'm doing this time code, basically you have to make three classes, one with normal time, one with 24 hour format and one with 12 hour. 24 and 12 hours should inherit from Base time class. And it should set the time too. For example if we enter 25 hours, it should automatically set it to 1. Same with the minutes. But I'm getting this weird error here ;

ERROR: conversion from ‘Atime*’ to non-scalar type ‘Atime’ requested

Actually i haven't studied C++ with OOP but Java. If anyone would help me I'll be thankful

ASSIGNMENT LINK : https://drive.google.com/open?id=1oW7sGE7pMMNjNv5OegeryE2qPIk_AZ_y

Here's The CODE:




#include <iostream>
using namespace std;

class Atime
{
private:
  int hours;
  int minutes;
public:
    Atime ()
  {
  }
  Atime (int h, int m)
   {
     setHours (h);
     setMinutes (m);
   }
  void setHours (int h)
   {
     hours = h;
   }
  void setMinutes (int m)
   {
   minutes = m;
   }
   int getHours ()
   {
    return hours;
   }
   int getMinutes ()
   {
   return minutes;
   }
   void print ()
   {
   cout << "Hours: " << hours;
   cout << "Minute: " << minutes;
   }
 };

class Mtime:public Atime
 {
   Mtime ()
  {
   }
   Mtime (int h, int m)
   {
     setHours (h);
     setMinutes (m);
   }
   void print ()
   {
    cout << "Hours: " << getHours ();
    cout << "Minute: " << getMinutes ();
   }
 };

 int main ()
 {
   Atime obj = new Atime (23, 23);




  }
  • 1
    `Atime obj = new Atime (23, 23);` That's really Java. :P In C++, `new` allocates memory (usually) and will return a pointer. `Atime obj = Atime(23, 23)` should be fine, or even `Atime obj(23, 23)`. I suggest going through some C++ tutorials or [grab a book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) to read up on how C++ works differently. – TrebledJ Jun 08 '19 at 03:00
  • Oh, I'm pretty dumb. I guess java just took over my mind. Thank you it's working!! – Muhammad Saad Ali Jun 08 '19 at 03:07

0 Answers0