float topspeed=-1.#QNAN0?!??!??!?!??!
Here''s a simple program i did while learning OOP.
class CVehicle //no base classes
{
friend class CWeathersystem;
private:
unsigned int weight,capacity;
float topspeed;
public:
void printdata();
unsigned int getweight(){return weight;}
unsigned int getcapacity(){return capacity;}
float gettopspeed(){return topspeed;}
int setweight(unsigned int newweight);
int setcapacity(unsigned int newcapacity);
int settopspeed(float newtopspeed);
};
this is the Vehicle class. CWeathersystem is a friend class that has a apply() function to apply weather to the Vehicle data (no real use just to learn OOP..)
class CWeathersystem
{
private:
float windspeed,rainrate,sunlight;
public:
int apply(CVehicle* pVehicle);
int setdefaults(float windspeed=10.0,float rainrate=25.0,float sunlight=1.21);
};
now the function int apply(CVehicle* pVehicle) applies the modifications to CVehicle class data:
int CWeathersystem::apply(CVehicle* pVehicle)
{
//check pointer is not null pointer
if(!pVehicle) return 0;
//modify CVehicle''s data using our private data
pVehicle->topspeed/=((1-rainrate)*(20-windspeed));
return 1;
}
so this is the problem: No matter what the values are at, apply() ALWAYS gives me a float topspeed result of -1.#QNAN0 ?!?
Doesn''t make any sense.
Well you should give your classes constructors to initialize their member variables. (Ie set your topspeed to it''s starting value in CVehicle::CVehicle())
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement