powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / Макросы в роде DECLARE_...
3 сообщений из 3, страница 1 из 1
Макросы в роде DECLARE_...
    #33724200
Normann
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Где должны быть DECLATE_DYNAMIC и IMPLEMENT_DYNAMIC? И должны ли они присутствовать одновременно? А DECLARE_DYNACREATE и IMPLEMENT_DYNACREATE? И еще DECLARE_SERIAL и IMPLEMENT_SERIAL?
...
Рейтинг: 0 / 0
Макросы в роде DECLARE_...
    #33724305
Фотография JibSkeart
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Хмм , а точнее ?
...
Рейтинг: 0 / 0
Макросы в роде DECLARE_...
    #33726069
Фотография Cerebrum
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
13.1.1. What's the difference between IMPLEMENT_DYNAMIC, IMPLEMENT_DYNCREATE and IMPLEMENT_SERIAL?
IMPLEMENT_DYNAMIC provides run time type information to support macros such as IsKindOf and GetRuntimeClass.


IMPLEMENT_DYNCREATE adds the ability to allow MFC to create the type on the fly. This is required for any concrete data type that will be serialized to a file.

IMPLEMENT_SERIAL also provides a version number for the class and adds the ability to use the >> operator to read the type from a file.

As an example, if a derived class Dog uses IMPLEMENT_DYNCREATE and a base class Animal uses IMPLEMENT_SERIAL, then a Dog can be written with a pointer to either but can only be read by a pointer to Animal.

MFC 3.x provides a constant called VERSIONABLE_SCHEMA to be used with IMPLEMENT_SERIAL to support multiple versions at the same time. The implementation in MFC is broken and fails at runtime.

jimb@turningpoint.com, email, 7/11/95

[MFC 4.0 NOTE: It is not true that the versionable schema is broken anymore, and has been fixed in MFC 4.0. ]

13.1.2. How can I declare an abstract base class to be IMPLEMENT_SERIAL?
You need a special form of IMPLEMENT_SERIAL that looks like this: Use the regular DECLARE_SERIAL but use IMPLEMENT_SERIAL_ABC shown below instead of IMPLEMENT_SERIAL.


#define IMPLEMENT_SERIAL_ABC(class_name, base_class_name, wSchema)
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, NULL)
CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb)
{
pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name));
return ar;
}
anonymous

13.1.3. I can't create an instance because of DECLARE_DYNCREATE!
Question : ClassWizard generated a class for me but used DECLARE_DYNCREATE(...) and declared my constructor as protected. Now, when a try to create an instance of the class I get the compiler error:

error C2248: 'CChkTbl::~CChkTbl' : cannot access protected member declared in class 'CChkTbl'

Answer : ClassWizard does this because the framework normally handles instantiation for you. i.e. if this is a CView derived class, normally the CDocumentTemplate instantiates the view during the default OnFileNew(), or when you call CxxxDocTemplate->OpenDocumentFile() or something similar. The framework does this so that it will give you an error message if you accidentally try to instantiate it yourself. If you really need to do instantiation outside of the CDocTempate framework, simply change the constructor to be public.

chucks@skypoint.com, programmer.tools, 8/12/95

Answer : The answer is that the DECLARE_DYNCREATE macro lays down a "protected:" directive and leaves it in place. One needs to make sure that anything following DECLARE_DYNCREATE should be "protected" too; if not, one needs to declare "public:" or "private:, as needed.

duane@anasazi.com, email, 8/15/95



--------------------------------------------------------------
Don't worry - wear Huggies
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / Макросы в роде DECLARE_...
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]