I'm doing a a program that converts time from 24 hours to 12 hours . I'm doing it using the constructor in class time 12 taking one argument which is of type class time 24 and making the conversion . I've got an error and I don't know where is the problem. Here is the constructor where the error occurs .

time12::time12(time24 t24)
{
	int hrs24=t24.getHrs();
	 pm = t24.getHrs()<12?false :true;     //find am / pm
	                                    // round seconds
	 min= t24.getSecs()<30? t24.getMins() :t24.getMins+1;
	if(min==60)                    //carry mins
	{
		min=0;
		++hrs24;
		if(hrs24==12 || hrs24==24)      //carry hrs
			pm=(pm==true)?false : true;  //toggle am/pm
	}
	hrs=(hrs24<13)?hrs24:hrs24-12;
	if(hrs==0)                   //o to 12 a.m
	{hrs=12;pm=false;}
	
}

there are two errors are for

min= t24.getSecs()<30? t24.getMins() :t24.getMins+1;

1)Error 1 error C3867: 'time24::getMins': function call missing argument list; use '&time24::getMins' to create a pointer to member c:\users\reem mandour\documents\visual studio 2008\projects\training5\training5\training5.cpp 113
2)Error 2 error C2296: '+' : illegal, left operand has type 'int (__thiscall time24:: * )(void) const' c:\users\reem mandour\documents\visual studio 2008\projects\training5\training5\training5.cpp 113


thank you
:)

Dani AI

Generated

Nice catch by — the two compiler errors were caused by omitting the function call parentheses on getMins. The compiler was telling you that t24.getMins was being treated as a member-function designator (not an int), so adding +1 tried to add to a function pointer type. Adding the missing () fixes both C3867 and C2296 immediately.

A couple of small, practical notes that go beyond the immediate fix:

  • Prefer taking the source time24 by const reference to avoid an unnecessary copy and to clarify intent:

    time12::time12(const time24 &t24) { /* ... */ }
  • Use pm = !pm; to toggle the boolean — it is clearer than the ternary expression.

  • Double-check time24::display() — it prints a trailing colon after seconds (you probably want a newline or nothing there).

  • Add simple input validation (reject negative minutes/seconds) or clamp values so malformed input cannot produce surprising results after rounding.

Quick debugging checklist for similar errors:

  1. Read the compiler message carefully — it often names the exact token causing trouble.
  2. Look for missing () on function calls or accidental use of the function name instead of its return value.
  3. Recompile after the small change; if errors persist, inspect types with a quick cast or temporarily print typeid(...) in a test.
  4. Consider enabling higher warning levels (MSVC /W4) — they catch common slips early.

Also, thanks to for asking for class declarations; having the declarations visible makes it trivial to spot the missing () and other small style improvements.

well , I've found the error :) IT'S SOMETHING SIMPLE I don't know how I didn't notice it . getMins()+1
thank you

Can we see the declarations of you time12 and time24 classes?

okay sure I'll show it to you although I've found the mistake and corrected it :)

class time24
{
	int hours;          //from 0 to 23
	int minutes;       //0 to 59
	int seconds;      //0 to 59
public:
	time24():hours(0) , minutes(0) , seconds(0)
	{    }
	time24(int h , int m , int s):hours(h) , minutes(m) , seconds(s)
	{    }
	void display()
	{
		if( hours<10)  cout<<'0';
		cout<<hours<<':';
		if( minutes<10)  cout<<'0';
		cout<<minutes<<':';
		if( seconds<10)  cout<<'0';
		cout<<seconds<<':';
		
		

	}
	//--------------------------------------------fuctions to access pvt members to be able make conv
	                                         //    using 1-arg constructor
         int getHrs()const   { return hours; }
		int getMins()const { return minutes; }
		int getSecs()const  { return seconds; }
	//----------------------------------
};
class time12
{
	bool pm;            //true=p.m , false=a.m
	int hrs;            //1 to 12
	int min;            //0 to 59
public:
	time12():pm(true) , hrs(0) , min(0)
	{    }
	//-------------
	time12(time24);//1-arg constructor that does the same job as convesion operator
	//-------------
	time12(bool ap , int h , int m):pm(ap) , hrs(h) , min(m)
	{  }
	 void display() const     //format :  11:59 p.m
	 {
		 cout<<hrs<<':';
		 if(min<10)
			 cout<<'0'; //extra 0 for "01"
		 cout<<min<<' ';
		 string am_pm = pm ? "pm" : "am";
		 cout<<am_pm;
	 }


};
time12::time12(time24 t24)
{
	int hrs24=t24.getHrs();
	 pm = t24.getHrs()<12?false :true;     //find am / pm
	                                    // round seconds
	 min= t24.getSecs()<30? 
		                    t24.getMins() :t24.getMins()+1;
	if(min==60)                    //carry mins
	{
		min=0;
		++hrs24;
		if(hrs24==12 || hrs24==24)      //carry hrs
			pm=(pm==true)?false : true;  //toggle am/pm
	}
	hrs=(hrs24<13)?hrs24:hrs24-12;
	if(hrs==0)                   //o to 12 a.m
	{hrs=12;pm=false;}
	
}
int main()
{
int h , m , s;
	while(true)
	{
		cout<<"Enter the 24 hours time: \n";
		cout<<"     Hours from (0 to 23) : "; cin>>h;
		if(h>23)    //quit if hours >23
			return(1);
		cout<<"minutes : ";cin>>m;
		cout<<"seconds : ";cin>>s;
		time24 t24(h,m,s);
		cout<<"you entered : ";t24.display();
		time12 t12=t24;
		cout<<"\n12-hour time: ";t12.display();
		cout<<"\n\n";
	}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.