"In VC"

xiaoxiao2021-03-06  92

Attributes are an indispensable element oriented in object-oriented programming, and the broad attribute is used to describe a state in which an object is in. The attributes whose article says this is narrow, indicating that a GET or SET operation is performed with a data of the class with the "=" operator, and can control GET and SET permissions. Let's take a look at the code:

#include

<

Iostream

>

#include

<

Map

>

#include

<

String

>

#include

<

Conio.h

>

Using

Namespace

STD;

Class

PropertyTest {

int

M_XValue;

int

M_YVALUES [

100

]; MAP

<

String

,

String

>

m_zvalues;

public

: __DECLSPEC (Property

get

=

Getx, PUT

=

PUTX))

int

X; __DECLSPEC (Property

get

=

Gety, put

=

PUTY))

int

Y []; __DECLSPEC (Property)

get

=

Getz, PUT

=

PUTZ))

int

z[];

int

Getx () {

Return

M_XValue;

Void

PUTX (

int

x) {m_xvalue

=

X;

int

GETY

int

N) {

Return

M_YVALUES [N];

Void

PUTY

int

n,

int

Y) {m_yvalues ​​[n]

=

Y;};

String

Getz

String

Key) {

Return

m_zvalues ​​[key];

Void

PUTZ

String

Key,

String

z) {m_zvalues ​​[key]

=

z; };};

int

Main

int

Argc,

charr

*

Argv []) {PropertyTest Test; Test.x

=

3

; Test.y [

3

]

=

4

; Test.z [

"

AAA

"

]

=

"

AAA

"

; Std :: cout

<<

Test.x

<<

Std :: endl; std :: cout

<<

Test.y [

3

]

<<

Std :: endl; std :: cout

<<

Test.z [

"

AAA

"

]

<<

STD :: endl; getch ();

Return

0

}

related articles:

What is the __Declspec in the VC - preface

Chapter 1 of the "__Declspec" in the VC (1) - Definition Interface

Chapter II "__DECLSPEC" can be made (2) - increasing attributes for class

转载请注明原文地址:https://www.9cbs.com/read-125141.html

New Post(0)