| |

VerySource

 Forgot password?
 Register
Search
View: 614|Reply: 4

Ask a C ++ question, please enlighten me

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-4 04:00:01
| Show all posts |Read mode
Following is the definition part of _IMPLEMENT_RUNTIMECLASS (class_name, base_class_name, wSchema, pfnNew):
static char _lpsz ## class_name [] = #class_name;\
        CRuntimeClass class_name :: class ## class_name = {\
                _lpsz ## class_name, sizeof (class_name), wSchema, pfnNew, RUNTIME_CLASS (base_class_name), NULL};\
        static AFX_CLASSINIT _init _ ## class_name (class_name :: class ## class_name);\
        CRuntimeClass * class_name :: GetRuntimeClass () const\
                {return&class_name :: class ## class_name;}\

AFX_CLASSINIT :: AFX_CLASSINIT (CRuntimeClass * pNewClass)
{
        pNewClass-> m_pNextClass = CRuntimeClass :: pFirstClass;
        CRuntimeClass :: pFirstClass = pNewClass;
}


What do the following two sentences mean? What can they do?
static AFX_CLASSINIT _init _ ## class_name (class_name :: class ## class_name);\
CRuntimeClass * class_name :: GetRuntimeClass () const\
                {return&class_name :: class ## class_name;}

I thanked him first
Reply

Use magic Report

0

Threads

30

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-1-5 17:09:01
| Show all posts
## is a string concatenation, in a parameter macro, for example:

#define FUNCTION_NAME (class_name) _init _ ## class_name

FUNCTION_NAME (CWnd) is expanded
_init_CWnd
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-7 19:54:01
| Show all posts
I know this, I do n’t know
static AFX_CLASSINIT _init _ ## class_name (& class_name :: class ## class_name);\
CRuntimeClass * class_name :: GetRuntimeClass () const\
                {return&class_name :: class ## class_name;}

The & class_name :: class ## class_name appearing before and after here, what is the connection between them. And, what does static do here specifically, does it declare a static global variable?
Reply

Use magic Report

0

Threads

30

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-1-7 23:00:01
| Show all posts
If you have read << Dive Into MFC >>, you will understand very well.
This is to declare and define a static runtime object for this class.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-10 13:09:01
| Show all posts
I was just looking at the profound things in a simple way. But I did n’t understand this part
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list