#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Class file with an error


    i created a class file call "time"
    with
    Code:
    #include <iostream>
    
    using namespace std;
    
    class Time{
    	float Hours;
    	float Minutes;
    	float Seconds;
    
    public:
    void setHours(float time){
    	Time.Hours = time/3600;
    	 
    }
    
    void setMinutes(float time){
    	Time.Minutes = time/60;
    }
    
    void setSeconds(float time){
    	Time.Seconds = time/60;
    }
    
    void timeInHours(){
    	return setHours(Hours);
    }
    
    void timeInMinutes()
    {
    	return setMinutes(Minutes);
    }
    
    void timeInSeconds()
    {
    	return setSeconds(Seconds);
    }
    
    };
    to convert from time between each time

    when i try to compile it here

    Code:
     
    
    #include <iostream>
    #include "time.h"
    
    using namespace std;
    
    int main()
    {
    	Time t;
    	t.setHours( 2 );
    	t.setMinutes( 40 );
    	t.setSeconds( 20 );
    	cout << "Time in seconds: " << t.timeInSeconds() << endl;
    	cout << "Time in minutes: " << t.timeInMinutes() << endl;
    	cout << "Time in hours: " << t.timeInHours() << endl;
    it shows me 2 errors

    1. error C2143: syntax error : missing ';' before '.'

    and

    2. no operator "<<" matchs these operands.

    i don't know why ..
    i'm a beginner
    i hope that i become like you guys.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,158
    Rep Power
    2222
    void functions don't return anything. << requires a return value. Your methods (OOP-speak for a class' functions) need to be declared as returning something and then also need to actually return something.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by dwise1_aol
    void functions don't return anything. << requires a return value. Your methods (OOP-speak for a class' functions) need to be declared as returning something and then also need to actually return something.
    thanks i got it
    i changed void to float .. and it worked

IMN logo majestic logo threadwatch logo seochat tools logo