Variables in classes
Jul 24, 2014 at 9:20am UTC
So I'm practicing some stuff with variables in classes and I can get it to work with string functions and words but when I try numbers I get loads of errors saying things like "no known conversion", help please!?!?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
using namespace std;
class PracticeClass
{
public :
void setNumber (int x)
{
number = x;
}
int getNumber()
{
return number;
}
private :
int number;
};
int main()
{
PracticeClass mo;
mo.setNumber(10);
cout << mo.getNumber;
return 0;
}
Last edited on Jul 24, 2014 at 9:22am UTC
Jul 24, 2014 at 9:22am UTC
mo.setNumber("10" );
you've told the compiler this function will take an int, yet you are passing it a string.
change to:
also line 26 needs to be:
you forgot the brackets.
Last edited on Jul 24, 2014 at 9:23am UTC
Jul 24, 2014 at 9:38am UTC
Program running well now, thanks!
Topic archived. No new replies allowed.