Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Флейм (http://www.flasher.ru/forum/forumdisplay.php?f=7)
-   -   protected в VC++6.0 == шо за бред??? =) (http://www.flasher.ru/forum/showthread.php?t=35486)

gOloVasTicK '~ 05.08.2002 18:19

protected в VC++6.0 == шо за бред??? =)
 
Вощем объявляю я в классе CCenteredDoc переменную StringData:
Код:

class CCenteredDoc : public CDocument
{
protected: // create from serialization only
        CCenteredDoc();
        DECLARE_DYNCREATE(CCenteredDoc)
        CString StringData;

А затем из метода другого класса CCenteredView::OnChar эту переменную изменяю :eek: :
Код:

void CCenteredView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
        CCenteredDoc* pDoc=GetDocument();
        ASSERT_VALID(pDoc);

        pDoc->StringData+=nChar;

Почему? =)
Она же протектед!
Или создание ссылки на объект дает возможность в его кишках копаться???
В общем чего то я не понял =)
Объясните плззз убогому ламеру..

kompadre 05.08.2002 19:08

Mozet potomuchto tvoy klass (kotoriy meniayet peremennuyu) - proizvodniy togo klassa v kotorom peremennaya?

CyberMax 05.08.2002 19:18

Не знаю, как в C++ (у Страуструпа упоминания ничего кроме public вообще не нашел), но в Delphi верно следующее:
Цитата:

A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears. In other words, a protected method can be called, and a protected field or property read or written to, from the definition of any method belonging to a class that descends from the one where the protected member is declared. Members that are intended for use only in the implementation of derived classes are usually protected.
Не помню, есть ли в C++ кейворд private.

RFMitrio 05.08.2002 19:21

Цитата:

Или создание ссылки на объект дает возможность в его кишках копаться???
Да, вроде так. А зачем тебе протектед? Может ты реально спутал с прайватом - протектед это не совсем "защищенный", он используется и удобен для организации иерархических классов.

kompadre 05.08.2002 19:21

Max ...
Ya ved o tom zhe ... proizvodniy(rus) == descendant(eng) ;)

Crazy 05.08.2002 20:00

Re: protected в VC++6.0 == шо за бред??? =)
 
Цитата:

Оригинал написал(а) gOloVasTicK '~
Почему? =)
Она же протектед!

Все в строгом соответствии со стандартом.

В C++ (как и в большинстве других подобных языков) модификаторы private/protected/public относятся не к экземплярам, а к классам. :)


Часовой пояс GMT +4, время: 00:10.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.