getters and setters

I've learned a bit about classes and once I was told not to modify variables in a class, but use getters and setters instead, they gave me this link: http://www.zeuscmd.com/tutorials/cplusplus/50-GettersAndSetters.php
ZeusCMD is a good site, it helped me understand classes much better.

Now as I hang around these forums I get to see many people saying that getters and setters are also bad, why? And what should I do instead? Modify those variables directly or use even different functions?
Who says getters and setters are bad? Without them, there is no need to use a class instead over a struct.

If you want to promote encapsulation, you need to use them.

I tend to just use the same name as the variable itself like:

1
2
3
4
5
6
private:
string _name;

public:
string Name( ) { return _name; }
string Name(string name) { _name = name; }

Hmmm... that's exactly what I do, but the other way round, like:
1
2
3
4
5
6
private:
string name;

public:
const string Name( ) const { return name; }
string Name(string _name) { name = _name; }

And I saw some people say that getters and setters defy the whole point of OOP. And I'm really not sure how OOP works, so can anyone give me a good site to explain the basics of Object Oriented Programming?
Topic archived. No new replies allowed.