Я создал простой класс для представления двери. Чтобы вернуть переменные, я обращаюсь к ним с помощью указателя this
. Что касается простого доступа к переменным, в чем разница между доступом к ним с помощью указателя this
и без него?
class Door
{
protected:
bool shut; // true if shut, false if not shut
public:
Door(); // Constructs a shut door.
bool isOpen(); // Is the door open?
void Open(); // Opens the door, if possible. By default it
// is always possible to open a generic door.
void Close(); // Shuts the door.
};
Door::Door()
{}
bool Door::isOpen()
{
return this->shut;
}
void Door::Open()
{
this->shut = false;
}
void Door::Close()
{
if(this->isOpen()) this->shut = true;
}
Здесь может быть или не быть разницы, но как насчет более сложных классов?