, , . . , , , - . , , , .
, , ( ), . . () , () .
. , . , , . .
, (overload) , . , . , , . , . - . .
, , , , , "Casio" , , , . , ( , ), ( , ). . , , . , ( ), . .
|
|
3.4
. , , , . , . , , , .
. , , . , C++, ( C++Builder - ).
3.4.1
C++Builder , , , . .
, . : private, protected public. 3.1 .
class className
private:
< > < > < >
protected:
< > < > < >
public:
< > < > > < > >
3.1. .
, C++ :
private , . .
protected , .
public , .
:
1. , .
2. , . - .
3. , . , .
4. , .
5. , . , .
|
|
6. ( ), C++, .
3.2 . C++Builder Count , SetCount, FCount - .
class TPoint { private:
int FCount; // void _fastcall SetCount(int Value);
protected:
_property int Count = //
{ read= FCount, write=SetCount };
double x; //
double ; // public:
TPoint(double xVal, double yVal); // |
double getX(); |
double getY();
3.2. TPoint.
( .h ., ). 3.3 , , . , , :
< >::< >
TPoint::TPoint (double xVal, double yVal)
(//
void _fastcall TPoint::SetCount(int Value)
{
l if (Value i= FCount) // ? {
FCount = Value; // Update(); // Update } } double TPoint::getX()
// getX, ^TPoint
}
3.3. .
, , (,
TPoint* MyPoint;).
3.4.2
, - , , - , . :
, .
.
, .
public, .
, .
new delete, .
3.4 .
class className
{ public:
// className(); // | className(< ;-);// | className(const className&); //
// "className(); //
// };
3.4. .
, . . , . :
. , , .
- , , ..
, . , . , (shallow copy constructors), . - , . "" .
|
|
, , , ~ (). . , .
, , . , , , . ( new), , , ( delete) ..
3.4.3
C++Builder , , , , . , , , , .
. : , . <
3.5 . : .
class className: [^ ;] parentClass {
<0 >
private:
< >
< >
< > protected:
< >
< >
< > public:
< >
< >
< >
< >
< > _published:
< >
< >
< >
3.5. .
_ published - , C++Builder ANSI C++ . , RTTI , C++Builder . 6 .
.
, . , :
|
|
private. (.. ) .
public. , .
, :
, , . . , , . , . , : , - .
- , TButtonControl C++Builder. .
. 3.1 , TButtonControl Draw : .
(. 3.2), SimpleButton, TButtonControl, Draw ( 3.6)
class SimpleButton: public: TButtonControl { public:
SimpleButton(int x, int y);
void Draw();
-SimpleButton() { }
};
SimpleButton::SimpleButton(int x, int y):
TButtonControl(x, y) { }
void SimpleButton::Draw()
{ ; outline->Draw();
}
3.6. .
SimpleButton - . SimpleButton:: Draw () ( ). , , TButtonControl.
(. 3.3). TextButton TButtonControl, Draw - . 3.3. , .
3.7 , title Text TextButton,
SimpleButton:-.Draw () . :
class Text { public:
Text(int x, int y, char* string) { } void Draw() { } };
class TextButton: public: TButtonControl {
Text* title;
public:
TextButton(int x, int y, char* title);
void Draw();
-TextButton() { });
TextButton::TextButton(int x, int y, char* caption)
TButtonControl(x, y) {
title = new Text(x, y, caption);
}
void TextButton::Draw () {
TextButton::Draw();
title->Draw();
}
3.7. .
C++ ( 3.8), : .
, - h- . Circle , Cylinder .
class SimpleButton: public: TButtonControl { public:
SimpleButton (int x, int y);
void Draw();
-SimpleButton() { } );
SimpleButton::SimpleButton(int x, int y):
TButtonControl(x, y) { }
I void SimpleButton::Draw()
I { i outline->Draw();
1)
3.6. .
SimpleButton - . SimpleButton:: Draw () ( ). , , TButtonControl.
(. 3.3). TextButton TButtonControl, Draw - . 3.3. , .
|
|
3.7 , title Text TextButton,
SimpleButton:: Draw () .
const double pi = 4 * atan(l);
class Circle { protected: