Thread: Error Description

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    Error Description

    Hello,
    Can somebody tell me what this error means?

    : error C2676: binary '*' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator

    I'm trying to create a function that calculates the cost of a tank of gas according to user input. I'm using multiple files so I'll show a snippet of the parts I've entered.

    Code:
    #ifndef _HEADER_H
    #define _HEADER_H
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    enum VehicleType{Automobile,Airplane,Train};
    enum FuelKind{Gasoline,JetFuel,Diesel};
    
    //==========================================
    
    struct VehicleInfo
    {
    	string RateOfSpeed;
    	string FuelCost;
    	string TankSize;
    	string mpg;
    };
    
    //============================================
    
    class CVehicle
    {
    protected:
    	VehicleInfo vinfo;
    	VehicleType type;
    	FuelKind ftype;
    	double CostFullLoad;  //new here
    
    public:
    	CVehicle(VehicleInfo, VehicleType t,FuelKind f);
    	CVehicle(){}               
    	void GetInfo();
    	void CalcFullLoadCost();  //new here
    	virtual void WriteData();
    };
    
    #endif
    That was the Header file.

    Code:
    void CVehicle::GetInfo()
    {
    	cout<<"\nEnter How Fast: ";
    	cin>>vinfo.RateOfSpeed;
    	cout<<"\nEnter Cost Per Gallon: ";
    	cin>>vinfo.FuelCost;
    	cout<<"\nHow many gallons will tank hold: ";
    	cin>>vinfo.TankSize;
    	cout<<"\nHow many miles per gallon: ";
    	cin>>vinfo.mpg;
    }
    
    //============================================
    
    //the error is on this line 
    
    void CVehicle::CalcFullLoadCost()  //new
    { CostFullLoad=(vinfo.TankSize * vinfo.FuelCost); }//new
    
    
    //============================================
    I am using a structure if that makes a difference. It doesn't seem to recognize the multiplication operator. Thank you for any help! MCorn

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    the error means exactly what it says: you cant multiply strings. did you want to convert the strings to numbers first and then mulitply them? or maybe store them as numbers in the first place?
    hello, internet!

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    34

    Smile

    Thank you Moi ! Is there some how to accomplish this with data casting...or something more on a beginner level? I impressed with your knowledge, however, you may as well be speaking Egyptian to me. I'd understand that just a well!

  4. #4
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Why not just make these data members integers (or floats) in the first place? Is there any specific reason why you declared them as strings?

    Code:
    struct VehicleInfo
    {
    	double RateOfSpeed;
    	double FuelCost;
    	double TankSize;
    	double mpg;
    };

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    34
    I guess the only reason I did that is because....I don't know ...I've been at it too long....or "idiot" comes to mind! Thanks for the help!

  6. #6
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by mcorn
    I guess the only reason I did that is because....I don't know ...I've been at it too long....or "idiot" comes to mind! Thanks for the help!
    Don't worry-- I spent my entire saturday night debugging. Oh what a wonderful life I lead.

Popular pages Recent additions subscribe to a feed