Archived

This topic is now archived and is closed to further replies.

float topspeed=-1.#QNAN0?!??!??!?!??!

This topic is 5901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Well you should give your classes constructors to initialize their member variables. (Ie set your topspeed to it''s starting value in CVehicle::CVehicle())

Share this post


Link to post
Share on other sites