Variables in classes

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
mo.setNumber("10");

you've told the compiler this function will take an int, yet you are passing it a string.
change to:
 
 mo.setNumber(10);


also line 26 needs to be:
 
cout << mo.getNumber();

you forgot the brackets.
Last edited on
Program running well now, thanks!
Topic archived. No new replies allowed.