Separate Class File Help

I SOLVED IT. GOT IT BOYS EHEHE NO NEED ANYMORE

So I need help on learning just exactly how theses separate classes work.
This is the code without separate classes which works just fine.
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
#include <iostream>
using namespace std;
  class Number{
public:
    void setNumber(int transfernumber){
    privatenumber = transfernumber;
    }
    
    int getNumber(){
    return privatenumber;
    }
private:
    int privatenumber;
};

int main()
{

Number key;
key.setNumber(200);
cout<<key.getNumber();

return 0;

}


Then when I create the separate class files. This is my code for the header and cpp

Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef NUMBER_H
#define NUMBER_H


class Number
{
    public:
        int getNumber();
        void setNumber();

    protected:
    private:
         int privatenumber;
};

#endif 


CPP File
1
2
3
4
5
6
7
8
9
10
#include "Number.h"
#include <iostream>
using namespace std;

Number::setNumber(int transfernumber){
    privatenumber = transfernumber;
    }
Number::getNumber(){
    return privatenumber;
    }


the int main stays the same. when i build the program it just says like the function setNumber and getNumber can't be matched or something like that


I'm not understanding how the source cpp file double semi colon is suppose to work. I thought that the cpp file is where the functions are suppose to go. and the header is the declarations. Did i mess up the function syntax? Thanks
Last edited on
Okay I finally messed around enough to get what's wrong with this now. I needed to add the data types void and int before the class Number and double semi colon. and I also need to declare the int transfernumber in the headerfile
Topic archived. No new replies allowed.