Advertisement

Constructors

Started by March 09, 2001 02:55 PM
2 comments, last by CHollman82 23 years, 10 months ago
Check this out ----------------------------------------------------------------- #include class test { private: float cx; public: test(float cx){}; outstats(){cout << "cx: "<What am I doing wrong?
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
No you have the wrong idea. Your constructor taking in a varialbe doesn''t assign it to that object''s variable. You have to pass in a number to your function and then assign that value to your object''s variable in the function like this:

class test
{
private:
int cx;

public:
test(int num) {cx = num;}
};
Advertisement
You never initialized cx in your class. It also doesn''t help that outstats doesn''t have a return type. Try this:
class test{private:float cx;public:test(float _cx){cx = _cx;};void outstats(){cout << "cx: "<};void main(){test one(1.1);one.outstats();} 


-Mike
-Mike
Yeah, I''m ignorant. Thanks guys.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();

This topic is closed to new replies.

Advertisement