You are on page 1of 35

2

OOP
C++ C++








. C++
C++

1
C++ C++



C++
2 :
:
class {
[ private]

protected

public

};

class ++
;
publicprotected private
private

autoregister extern static

C++

const const

private
private

public
public
private
protected

class Window
{ public:
Window(int x, int y, int h, int w);//
~Window(); //
void OpenWindow(); //
private: int X, Y, H, W; //
};

C++
#include <iostream.h>
class person // person
{public:
char * name;
int height; //

int weight; //
};
void main()
{ person Zhang_three; // Zhang_three
Zhang_three.name = ""; // Chang_three
Zhang_three.height = 175; // Chang_three 175
Zhang_three.weight = 60; // Chang_three 60

cout << " : " << Zhang_three.name


<< "\n : " << Zhang_three.height
<< "\n : " << Zhang_three.weight << endl;
}

C++
#include <iostream.h>
#include <iostream>
class Student
{ private:
int num; int score;//
public:
void setdata()//
{ cin>>num; cin>>score;
}
void display()//
{ cout<<"num="<<num<<endl;
cout<<"score="<<score<<endl;
};
};
Student stud1,stud2;
int main()
{ stud1.setdata(); stud2.setdata();
stud1.display(); stud2.display();
return 0;
}

class struct C
C


C
numcore setdatadisplay
Student
numcore
setdatadisplay

stud1 stud2
setdata display


1
2
----int Hour, int Minute, int Second;
----SetTime()Showtime();
3
class TimeClass //
{ public: // public
void SetTime(int NewH, int NewM, int NewS);
void ShowTime();
protected: // protected
private: // private
int Hour; int Minute; int Second;
};
4
void TimeClass::SetTime(int NewH, int NewM, int NewS)
{ Hour=NewH; Minute =NewM; Second =NewS;
}
void TimeClass::ShowTime()
{ cout<<Hour <<: <<Minute <<:;
cout<<Second<<endl;
}
5
#include iostream.h
void main(void)
{ TimeClass myWatch;
myWatch.SetTime(8,30,0);
myWatch.ShowTime();
cin.get(); //pause
}

C -----

public protected private


private
class TimeClass
{ void SetTime(int NewH, int NewM, int NewS);
void Showtime();
int Hour, int Minute, int Second;
}; // private
3
1



< > < >;

class Window
{ private: int X,Y,Z //
}
int X,Y,Z //
2
public
public private






::
::


< ><
< > <><>

{ //
}

class Window //
{ public:
Window() //
{
}
void Function() //
}
void Window::Function()
Window:: //::
{
}


disp() disp()
disp

#include <iostream.h>
class person // person
{public:
char * name;
int height; //
int weight; //
void After_OneYear() //
{ height += 10;
weight -= 10;
}
};
void main()
{ person Zhang_three; // Zhang_three
Zhang_three.name = " "; // Zhang_three
Zhang_three.height = 175; // Zhang_three 175
Zhang_three.weight = 60; // Zhang_three 60
Zhang_three.After_OneYear(); //
cout << " : " << Zhang_three.name
<< "\n : " << Zhang_three.height
<< "\n : " << Zhang_three.weight << endl;
}

class person // person
{public:
char * name;
int height; //
int weight; //
void After_OneYear(); //
};
void person::
person::After_OneYear() //::
{ height += 10;
weight -= 10;
}
4 TimeClass
1 public
public
2 private
private
3 protected private


public private

5
1

2

. public
-> public

:
#include "iostream.h"
#include graphics.h
class Window //
{ public:
void OpenWindow();//
long Area() //
{ return H*W;// H W
}
Window() //
{ X=100;Y=100;W=5;H=5;
}
private: int X,Y,W,H;
};
void Window::OpenWindow()//
Window::
{ rectangle(X,Y,X+W+100,Y+H+100); //X,Y,W,H
cout<< Area=<<Area(); //
}
void main()
{ int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\bc31\\bgi"); //
setcolor(2);
Window myWin;
cout<<myWin.Area();
myWin.OpenWindow();
//public .
//myWin.X=10; //private
cin.get(); //pause
closegraph();
}

2:
#include "iostream.h"
#include string.h
class Student //
{ public:
void set(int a,char *b) //
{ number=a;
strcpy(name,b);// number name
}
void disp() //
{ cout<<<<number<< <<name<<endl;
}
private:
int number; char name[20];
};
void main()
{ Student student,*p; // student Student p
p=&student; // p student
student.set(9901, ); //. set
student.disp(); //. disp
p->disp(); // p -> disp
}

9901
9901
student.disp(); p->disp();
3:



#include "iostream.h"
const int MAX=50;
class queue
{ private:
int q[MAX]; //
int head,tail; //
public:
void initialize();
void insertq(int value);
int deleteq(); int gethead(); int gettail();
};
void queue::initialize()
{ head=0; tail=0;
}
void queue::insertq(int value)
{ if(tail==MAX)
{ cout<< <<endl;}
else
{ tail++; q[tail]=value;}
}
int queue::deleteq()
{ if(head==tail)
{ cout<< <<endl;}
else
{ head++; return q[head];}
}
int queue::gethead()
{ return head;}
int queue::gettail()
{ return tail;}
void main()
{ queue data; int x;
data.initialize();
cout<< ;
cin>>x;
while(x!=0) // 0
{ data.insertq(x);
cin>>x;
}
cout<< <<endl;
while(data.gethead()!=data.gettail())
cout<<data.deleteq()<<endl;
}

100
200
300
0

100
200
300
. C++
C++
1


2

----
----
---- ID
----
3 C++
C++

2-1

2-1
class Car {
int color_number;
int door_number;
int speed;

void brake() { }
void speedUp() {};
void slowDown() { }
}


C++
---
4


1

class {
//
} 1 2 ; //

C++
2

//

Window myWincopyWin;

new delete
new new delete C++

new <> [(<>)];


C++

delete
delete <>;

delete [] <>;
5
1
2
""
"->"

public
" "

#include <iostream.h>
class A
{public:
void init(int i=0,int j=0) //
{a=i;b=j;}
void CPrint(); //
private:
int a,b;
};
void A::CPrint() //
{ cout<<The figure you get:<<a<<","<<b<<endl; }
void main()
{ A a1, a2;
a1.init(7,8);
a2.init(10,11);
a1.CPrint();
a2.CPrint();
//cout<<sizeof(a1)<<endl; //
//cout<<sizeof(a2)<<endl;
}

The figure you get:7,8


The figure you get:10,11

a1 a2
a1.a 7 a2.a 10
a1.b 8 a2.b 11
a1.init() a2.init()
a1.CPrint() a2.CPrint()


3
10 10
2 2


10 10

C++
23

:
#include <iostream.h>
class A
{ public:
A(int i=0,int j=0){a=i;b=j;} //
void CPrint();
private:
int a,b;
};
void A::CPrint()
{ cout<<The figure you get:<<a<<","<<b<<endl; }
void main()
{
The figure you get:5,9
A a1(7,8),a2(1),a3(5,9); The figure you get:1,0
A *b[3]={&a3,&a2,&a1}; The figure you get:7,8
for(int i=0;i<3;i++)
b[i]->CPrint();
}

:
#include <iostream.h>
class A
{public:
void init(int i=0,int j=0) //
{a=i;b=j;}
void CPrint(); //
private:
int a,b;
};
void A::CPrint() //
{ cout<<The figure you get:<<a<<","<<b<<endl; }
void main()
{ The figure you get:7,8
The figure you get:7,8
A a1; a1.init(7,8);
A &ra=a1; //
ra.CPrint(); a1.CPrint();
}

class Test
{public:
//
void set(int a) { value= a;}
int get(void) {return value; }
private:
int value;
};
2-3
C++
inline
inline
class Test
{public:
//
void set(int a);
void get(void);
private:
int value;
};
//
inlinevoid Test::set(int a)
{ value= a;
}
inline int Test::get(void)
{return value;
}
inline

C++

1
#include <iostream.h>
class COMPLEX
{ double r,v;
public:
COMPLEX(double rp, double vp) //
{ r=rp; v=vp; }
inline double getr(); //inline
double getv();
};
inline double COMPLEX::getv() //
{ return v; }
inline double COMPLEX::getr() //
{ return r; }
void main()
{ COMPLEX c(3,4);
double r=c.getr();
double v=c.getv();
cout<<r<<i<<+<<v<<endl;
}
.



class TV
{ public:
void setChannel(Remoter Obj) // TV
{
}
void setChannel(Hand Obj) // TV
{
}
}

timer settimer
#include <iostream.h>
#include <stdlib.h>
class timer{ // timer
long minutes;
public:
void settimer(char *m) { //
minutes = atoi(m); //
};
void settimer(int h, int m) { //
minutes = 60*h+m ;
};
void settimer(double h) { //
minutes = (int) 60*h ;
};
long getminutes(void) { return minutes ; };
};
int main(void){
timer start,finish; //
//
start.settimer(8,30);
finish.settimer(17,30);
cout<<finish.getminutes()-start.getminutes()<<endl;
//
start.settimer("60");
finish.settimer(11.0);
cout<<finish.getminutes()-start.getminutes()<<endl;
return 0;
}
2

class Window
{ public: //
void OpenWindow(int x=10, int y=10)// void OpenWindow(int=10, int=10)
long Area() //
{ return H*W
}
private: int X,Y,W,H
} // inline
inline void Window::OpenWindow(int x, int y)
{
}


#include <iostream.h>
class A
{ public:
void init(int i=0,int j=0) {a=i;b=j;}
void CPrint();
private:
int a,b;
};
void A::CPrint()
{ cout<<The figure you get:<<a<<","<<b<<endl;
}
void main()
{ The figure you get:7,8
A a1,a2,a3; The figure you get:9,0
The figure you get:0,0
a1.init(7,8); a2.init(9); a3.init();
a1.CPrint(); a2.CPrint(); a3.CPrint();
}


COMPLEX(double=10, double=20)
COMPLEX()
COMPLEX(double)

COMPLEX c1; //
COMPLEX c2(15); //

. C++
C++ this
n
n n
this
this


this this this
this this

this
C++





void init(int i,int j) C++ void init(A *this,int i,int j)
{a=i;b=j;} { this->a=i; this->b=j;}

this this

this
#include <iostream.h>
class Example
{ private: int m;
public:
void setvalue(int arg1){ m= arg1; }
void disp(){ cout<<m=<<m<<endl; }
};
void main()
{ Example s;
s.setvalue(100);
s.disp();
}
s.setvalue(100); setvalue s m 100
void setvalue(Example *this,int arg1){ this->m= arg1;
}
s.setvalue(100); setvalue(&s,100);
setvalue s this this s
m
this

*const this;


this

class Window
{ public:
Window(int X, int Y, int H, int W) //
{ this->X=X this->Y=Y
this->H=H this->W=W
}
private: int X,Y,H,W //
}

# include <iostream.h>
class Tdate
{ private: int month;
public:
Tdate(int month)
{ this->month = month;
cout << this->month << endl;
}
};
void main()
{ Tdate * b = new Tdate(10); // Tdate(int m)
delete b;
}
this
class Window
{ public: Window(Window & Win)
{ X=Win.X
Y=Win.Y
H=Win.H *this=Win
W=Win.W
}
private: int X,Y,H,W
}

*this

=
class Window //
{public:
Window(Window & Win)
{ *this=Win; // Title
}
Window & operator=(Window &Win) //=
{ X=Win.X Y=Win.Y H=Win.H W=Win.W
Title=new char[20]
strcpy(Title, Win.Title) // Title=Win.Title
}
private: int X,Y,H,W
char *Title
}
this
C++
this this

Window winA, winB
winA.GetX()-->winA.GetX() ---->winA.GetX()
{ return X; {return this->X --->return winA.X
} }

winB.GetX()-->winB.GetX() ---->winB.GetX()
{ return X; { return this->X ---> return winB.X
} }

#include <iostream.h>
#include graphics.h
class Window //
{ public:
void CopyWindow(Window &WinObj)
{ if( this != &WinObj) //
{ X=WinObj.X;
Y=WinObj.Y; // *this= WinObj
H=WinObj.H;
W=WinObj.W;
}
else {cout<<Dont copy self ! <<endl; return; }
}
Window(int x,int y,int w,int h) //
{ X=x;Y=y;W=w;H=h; }
void OpenWindow();
private:
int X,Y,H,W;
};
void Window::OpenWindow()
{ rectangle(X,Y,X+W,Y+H); //X,Y,W,H
}
void main()
{ int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\bc31\\bgi"); //
Window winA(100,100,300,300), winB(200,200,200,200);
setcolor(2); winA.OpenWindow();
setcolor(4); winB.OpenWindow();
winA.CopyWindow(winA); //
winA.CopyWindow(winB); //
setcolor(8); winA.OpenWindow();
cin.get(); //pause
closegraph();
}

1this *this
#include "iostream.h"
class Sample
{ int n;
public:
Sample(){}
Sample(int m){ n=m; }
Sample add(Sample s1, Sample s2)
{ this->n=s1.n+s2.n;
return(*this);
}
void disp(){ cout<<n=<<n<<endl; }
};
void main()
{ Sample s1(10),s2(5),s3;
cout<<s1:; s1.disp();
cout<<s2:; s2.disp();
s3.add(s1,s2);
cout<<s3:; s3.disp();
}
s1:n=10
s2:n=5
s3:n=15
1 Sample add(Sample &s1, Sample s2)
s3=s3.add(s1,s2);
2 addarea()

2this *this
#include "iostream.h"
class A
{ public:
A(){ a=b=0; } //
A(int c,int d){ a=c;b=d; } //
void copy(A &aa);
void print(){cout<<a<<,<<b<<endl;}
private: int a,b;
};
void A::copy(A &aa)
{ if(this==&aa) return; // this
*this=aa; //*this
}
void main()
{ A a1,a2(4,5); a1.print();
a1.copy(a2); a1.print();
}
0,0
4,5
.
C++
1
C ---- C++----

C+
+

struct {

}

#include <iostream.h>
struct animal
{ int weight; int feet;
};
void main()
{ animal dog1, dog2, chicken;
dog1.weight = 15; dog2.weight = 37;
chicken.weight = 3;
dog1.feet = 4; dog2.feet = 4;
chicken.feet = 2;
cout << "The weight of dog1 is " << dog1.weight << "\n";
cout << "The weight of dog2 is " << dog2.weight << "\n";
cout << "The weight of chicken is "<< chicken.weight << "\n";
}


C++ 1 C++
C++
C++
#include <iostream.h>
struct animal
{ private: int weight; int feet;
public:
int GetWeight();
void init(int w,int f);
};
void animal::init(int w,int f){ weight=w; feet=f; }
int animal:: GetWeight(){ return weight; }
void main()
{ animal dog1, dog2, chicken;
dog1.init(15,4); dog2.init(37,4); chicken.init(3,2);
cout << "The weight of dog1 is " << dog1.GetWeight() << "\n";
cout << "The weight of dog2 is " << dog2.GetWeight() << "\n";
cout << "The weight of chicken is "<< chicken.GetWeight() << "\n";
}

public
class
private

2
#include <iostream.h>
struct
{ int x;
int random() //
{ return x=(23*x+19)%101; }
}r={1};
void main()
{ for(int i=0;i<10;i++)
cout<<r.random()<<endl;
}

2

1

union


:
union data
{
int i;
char ch;
float f;
}
data

2


.
3
C++ union
union
{ int i;
float f;
};
i f

class CU
{ union
{ int i;
float f;
};
//
}

1

2
3

:
#include <iostream.h>
class aircraft
{ public:
int wingspan;//
int passengers; //
union //
{ float fuel_load; //
float bomb_load; //
};
} fighter,bomber;
void main()
{ fighter.wingspan = 40;
fighter.passengers = 1;
fighter.fuel_load = 12000.0;
//fighter.bomb_load = 14000.0;
bomber.wingspan = 90;
bomber.passengers = 12;
bomber.bomb_load=16000.0;
cout<<fighter.fuel_load:<<&fighter.fuel_load;
cout<< <<fighter.fuel_load<<\n";
//cout <<fighter.bomb_load:<<& fighter.bomb_load ;
//cout<< << fighter.bomb_load << "\n";
cout <<bomber.bomb_load:<<& bomber.bomb_load ;
cout<< << bomber.bomb_load << "\n";
}

.
. .
1

class MyClass
{ private:
int num;
public:
void set(int i) ;
};
int i=num; //num
int num; //num num
void MyClass:: set(int i)
{
num=i; // MyClass num
}




void MyClass:: set(int i)
{
MyClass::num=i; // MyClass num
}


#include <iostream.h>
class MyClass
{ public:
int a;
enum boolean{ FALSE,TRUE };//{ FALSE=7,TRUE=8 };
int fun(MyClass &x) ;
};
int MyClass::fun(MyClass &x)
{ x.a=x.FALSE; //x.a= MyClass::FALSE;
return x.a;
}
void main()
{
MyClass A,B;
A.a=11; B.a=50;
B.a=B.fun(B);
cout<< A.a<< <<A.FALSE<<endl;
cout<< B.a<< <<B.FALSE<<endl;
}

2
C++

class
1class A; //
A obj; //
A *objptr; //
void fun(A obj); //

2class MyClass
{private:
MyClass member; // MyClass
MyClass *P; //
}
class YourClass
{ private:
MyClass obj; //
};
C++

. .
C++
// Empty
class Empty
{ };
// main()
void main()
{ Empty a,*p; //
}

. .

1 1 2
2= 1
Window winOne,winTwo;
winTwo=winOne;


#include <iostream.h>
class animal
{ private:
int weight; int feet;
public:
int GetWeight();
int GetFeet();
void init(int w,int f);
};
void animal::init(int w,int f)
{ weight=w; feet=f; }
int animal:: GetWeight()
{ return weight; }
int animal:: GetFeet()
{ return feet; }
void main()
{ animal dog1, dog2;
dog1.init(15,4); dog2=dog1;
cout << "The dog1 is " <<feet=<<dog1. GetFeet()<< weight=<<dog1.
GetWeight() << "\n";
cout << "The dog2 is " <<feet=<< dog2. GetFeet()<< weight=<< dog2.
GetWeight() << "\n";
}
2

3 .


1
[]
Window ArrayName[10];
2
0 n-1
[].
ArrayName[0].OpenWindow();
3

#include "iostream.h"
#include graphics.h
class Window
{ public: Window(int x, int y, int h, int w) //
{ X=x, Y=y, H=h, W=w;
}
void OpenWindow(); //
void MoveWindow(int NewX1, int NewY1);
private: int X,Y,H,W;
};
void Window::OpenWindow() //
{ rectangle(X,Y,X+W,Y+H);
}
void Window::MoveWindow(int NewX,int NewY)
{ cleardevice();
X=NewX,Y=NewY; OpenWindow();
}
void main()
{ int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\bc31\\bgi"); //
setcolor(2);
Window WinArray[2]= {Window(10,10,200,200), Window(20,20,300,300)};
// WinArray[0]=Window(10,10,200,200);WinArray[1]=Window(20,20,300,300);
for(int i=0;i<2;i++)
{ setcolor(3+i);
WinArray[i].MoveWindow(10*i+100, 100*i);
cin.get();//pause
}
closegraph();
}
4

---
---
---
5
NULL
..
#include "iostream.h"
#include graphics.h
#include string.h
class Window
{ public:
void OpenWindow(int x, int y, int h, int w)
{ Title=new char[20];
strcpy(Title," Window Title ");
cout<< Title<<endl;
rectangle(x,y,x+w, y+h);
cin.get();
}
~Window()
{ if(Title !=NULL) // NULL
delete []Title;
}
private: char *Title;
};
void main()
{ int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\bc31\\bgi"); //
setcolor(2);
Window WinArray[2];
WinArray[0].OpenWindow(100,100,200,200);
setcolor(4);
WinArray[1].OpenWindow(150,150,300,300);
cin.get();
closegraph();
}

1 C/C++
C/C++

1 *
int * ptr;
2
int X=1;
int *ptr=&X; // ptr X


1: int X=1
int *ptr
*ptr=3 // ptr
cout << X
2: int *ptr=new int(3)
cout<<*pt
delete ptr // ptr
cout << *ptr // ptr ptr
2 C++
C++C++
1 *
Window *ptr
2


=&
void main()
{ Window winOne(10,10,200,200)*ptr
ptr=&winOne //winOne
}



new delete
=new
=new
void main()
{ Window *ptr //
ptr=new Window(10,10,200,200)
//new
ptr -> OpenWindow() //
delete ptr //
}

new delete !
3
->
ptr -> OpenWindow()
4
Window *ptr=new Window[5]

ptr[0].OpenWindow() //
ptr ->OpenWindow() //
ptr+1; //
(*ptr).OpenWindow() //
delete [] ptr


#include "iostream.h"
#include graphics.h
class Window
{ public:
void OpenWindow(int x, int y, int h, int w)
{ rectangle(x,y,x+h, y+w); cin.get();
}
};
void main()
{ int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "\\bc31\\bgi"); //
setcolor(2);
Window *ptr=new Window[5] ;//
ptr->OpenWindow(100,100,200,200) ; //
setcolor(4);
ptr[1].OpenWindow(200,200,150,150); //
delete [] ptr;
}
3 C++
C++
* []

#include "iostream.h"
class A
{ public:
A(int i=0,int j=0){ a=i;b=j; }
void print();
private:
int a,b;
};
void A::print()
{ cout<<a<<,<<b<<endl; }
void main()
{ A a1(7,8),a2,a3(5,7);
A *b[3]={ &a3,&a2,&a1 };
for(int j=0;j<3;j++)
b[j]->print();
}
4



void ShowArea(Window win) //
{ cout<<"Area Is= " << win.Area()<<endl;
}

#include "iostream.h"
class Window
{ public:
long Area()
{ return H*W };// H W
void ShowArea(Window win) //
{ cout<<"Area Is= " << win.Area()<<endl;
win.W=10; win.H=10;
cout<<"Area Is= " << win.Area()<<endl;
}
Window() //
{ W=5;H=5; }
private: int W,H;
};
void main()
{ Window myWin; cout<<myWin.Area()<<endl;
myWin.ShowArea(myWin);
cout<<myWin.Area()<<endl;
cin.get(); //pause
}
25
Area Is= 25
Area Is= 100
25

void ShowArea(Window & win) //
{ cout<<"Area Is= " << win.Area()<<endl;
}


C++

#include "iostream.h"
class Window
{ public:
long Area()
{ return H*W; }// H W
void ShowArea(Window &win) //
{ cout<<"Area Is= " << win.Area()<<endl;
win.W=10; win.H=10;
cout<<"Area Is= " << win.Area()<<endl;
}
Window() //
{ W=5;H=5; }
private: int W,H;
};
void main()
{ Window myWin; cout<<myWin.Area()<<endl;
myWin.ShowArea(myWin);
cout<<myWin.Area()<<endl;
cin.get(); //pause
}
25
Area Is= 25
Area Is= 100
100

2:
#include "iostream.h"
class M
{public:
M(){ x=y=0; } //
M(int i,int j) { x=i;y=j; } //
void copy(M &m){ x=m.x; y=m.y; }
void setxy(int i,int j) { x=i;y=j; }
void print(){ cout<<x<<,<<y<<endl; }
private:
int x,y;
};
void fun(M m1,M &m2); //
void main()
{ M p(5,7),q;
q.copy(p); fun(p,q);
p.print(); q.print();
}
void fun(M m1,M &m2)
{ m1.setxy(12,15);
m2.setxy(22,25);
}
5,7
22,25

void ShowArea(Window *win) //
{ cout<<"Area Is= " << win->Area()<<endl;
}

:#include "iostream.h"
class Window
{ public:
long Area()
{ return H*W; }// H W
void ShowArea(Window *win) //
{ cout<<"Area Is= " << win->Area()<<endl;
win->W=10; win->H=10;
cout<<"Area Is= " << win->Area()<<endl;
}
Window() //
{ W=5;H=5; }
private: int W,H;
};
void main()
{ Window myWin; cout<<myWin.Area()<<endl;
myWin.ShowArea(&myWin);
cout<<myWin.Area()<<endl;
cin.get(); //pause
}
25
Area Is= 25
Area Is= 100
100

2:
#include "iostream.h"
class M
{public:
M(){ x=y=0; }
M(int i,int j) { x=i;y=j; }
void copy(M *m);
void setxy(int i,int j) { x=i;y=j; }
void print(){ cout<<x<<,<<y<<endl; }
private:
int x,y;
};
void M::copy(M *m)
{ x=m->x;
y=m->y;
}
void fun(M m1,M *m2);
void main()
{ M p(5,7),q;
q.copy(&p);
fun(p,&q);
p.print(); q.print();
}
void fun(M m1,M *m2)
{ m1.setxy(12,15);
m2->setxy(22,25);
}
5,7
22,25

1
2

5 max max 5


Window getWindow() //
{ Window win(10,10,200,200)
return win
}

1

2

autoregisterextern static
.

. .
C++


#include<iostream.h>
// outer inner
class outer //
{ public:
class inner { // outer inner
int value;
public:
void set(int n) {value=n;}
void disp() {cout<<value<<endl;}
};
void set(int n) {w=n;}
void disp() {cout<<w<<endl;}
private: int w;
};
// main()
void main()
{ outer::inner ex; // ex
ex.set(100);ex.disp();
outer px;
px.set(50);px.disp();
}
100
50

. .

You might also like