Set & Get methods

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

class books{
public:
void setName(string name){
name = The New Particle;
}
string getName(){
return name;
}
void setDate(int date){
date = 12/03/1963;
}
int getDate(){
return Date;
}
private:
string bookName(string name);
int releaseDate(int date);
};


Hi. Above is an example of using Set & Get methods. However, I have hit a brick wall, as I don't fully understand, if one has to call the Set & Get method in the main function or it is fine not to call the Set & Get method in the main function?

Does this code Date.get return the date or does it do something else?

Sorry for the long essay. I have watched instructional videos on YouTube and read a book, but I am still confused.

I appreciate any help given and would like to thank everyone taking their time to help.
Last edited on
Your example is invalid because it will not be compiled.
Nevertheless you can call these methods anywhere you want.
Last edited on
Topic archived. No new replies allowed.