C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 26th, 2003, 02:31 PM
Tozilla Tozilla is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 21 Tozilla User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 52 m 59 sec
Reputation Power: 0
Operator overloading,initization, Print() in header file

I'm currently writing a header file for a Car class. But The problem is I don't know how to initialized in the Car class and use the copy constructor in the header file. Also, this header file requires a operator function. When I compile it, I have a syntax errors for those two operator function. For the Print() method, I have to use it for display the mantfacturere, model, year, total manufacture, total kilometers travelled and the amount of fuel costs, total number of services and fuel economy with print method. Can anyone please take a look at my code and help me fixing some of the mistakes in the header file?

Thank you

PHP Code:
#ifndef CAR_H
#define CAR_H
#ifndef LEN
#define LEN 25

class Car
{    
       private:
           
char name[LEN]; 
           
char model[LEN]; 
           
int year;
    
       public:
            
Car();
            
Car(char *mchar *nint y);
            
Car(const Car &source);              //copy constructor
            
const Car operator +(const Journeymeter) const;
            const 
Car operator +(const FuelPurchaseamount) const;
            
void print(void) const;        
            ~
Car();
};
#endif 

Last edited by Tozilla : March 26th, 2003 at 10:04 PM.

Reply With Quote
  #2  
Old March 26th, 2003, 09:32 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 10
Re: Operator overloading,initization, Print() in header file

PHP Code:
const Car operator +(const Journeymeter) const;
const 
Car operator +(const FuelPurchaseamount) const; 
Should be:
PHP Code:
const operator +(const Journeymeter) const;
const 
operator +(const FuelPurchaseamount) const; 

Reply With Quote
  #3  
Old March 30th, 2003, 04:42 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,365 7stud User rank is Private First Class (20 - 50 Reputation Level)7stud User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 12
You sure about that Jason Doucette?

Reply With Quote
  #4  
Old March 30th, 2003, 12:54 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 10
Re: Re: Operator overloading,initization, Print() in header file

You're right, I am wrong.

I thought he was using the class name and forgetting the scope resolution operator ::, which is only needed in the definition outside of the class. I didn't look at it carefully enough. The only thing wrong with his code is the const at the start. His code should be:

Code:
Car operator +(const Journey& meter) const;
Car operator +(const FuelPurchase& amount) const;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Operator overloading,initization, Print() in header file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap