Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

WxWidgets lesson 2 DECLARE_NO_COPY_CLASS forbids copying of classes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Description

In the defs.h file, the macro is defined as follows

# define DECLARE_NO_COPY_CLASS (classname)\

WxDECLARE_NO_COPY_CLASS (classname)

The actual definition of wxDECLARE_NO_COPY_CLASS is as follows:

# define wxDECLARE_NO_COPY_CLASS (classname)\

Private:\

Classname (const classname&);\

Classname& operator= (const classname&)

From the expansion of the macro definition above, the copy constructor and equal sign operation operator of the class are set to private member functions, which prohibits any copy outside the class.

Usage

Class BaseFrame

{

DECLARE_NO_COPY_CLASS (BaseFrame)

Public:

BaseFrame ()

Virtual ~ BaseFrame ()

}

Expand as follows:

Class BaseFrame

{

Private:

BaseFrame (const BaseFrame&)

BaseFrame& operator= (const BaseFrame&)

Public:

BaseFrame ()

Virtual ~ BaseFrame ()

}

Be careful

In the header file, the variable name in the parameter list of the function is not important and may not be written. The declaration of the function can be different from the list variable name of the implementation, but the type of the variable must be the same.

IMPLEMENT_DYNAMIC_CLASS

Code

# define IMPLEMENT_DYNAMIC_CLASS (NMagneb) wxIMPLEMENT_DYNAMIC_CLASS (nMagneb)

/ / Single inheritance with one base class

# define wxIMPLEMENT_DYNAMIC_CLASS (name, basename)\

WxIMPLEMENT_CLASS_COMMON1 (name, basename, name::wxCreateObject)\

WxObject* name::wxCreateObject ()\

{return new name;}

Description

Support for run-time class information is mainly to determine whether an object belongs to or is derived from the implementation of a particular class

This macro definition will cause compilation errors when introducing windows.h header files, so it needs to be used with caution.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report