Constructors
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;}
};
class test
{
private:
int cx;
public:
test(int num) {cx = num;}
};
You never initialized cx in your class. It also doesn''t help that outstats doesn''t have a return type. Try this:
-Mike
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement