Uroci.net - !
Adobe Photoshop Adobe Illustrator Adobe Flash Adobe Fireworks DreamWeaver CSS HTML Corel Draw Image Ready PHP SEO CMS Microsoft Windows Microsoft Word Microsoft Excel PowerPoint Microsoft Access Microsoft Publisher Linux Visual basic JavaScript Ajax 3ds Max Maya 3D C++
C++
Sound Forge Gimp SWiSH

C++ .7 ( )

C++ » C++
fix3d   :    : 6960





, , . , String Stirng::strin(int) :

class Stirng {
friend class Buf;
public:
String( char* );
String();

private:
String( int ); // ... rest of Stirng class };

String Buf String, int. String, char*.

f() { // ok: String::String( char* ) is public
String search( "rosebud" ); { // ok: String::String( char* ) is public
private
String inBuf( 1024 );
... }

Buf::in() // error: String::String( int ) is
String search( "rosebud" );
// ok: String::String( int ) is private
// Buf is a friend to String
String inBuf ( 4096 );
... }

. . IntItem, 5.2 . IntItem IntList, IntItem.



++ , , . , , , , delete . , , . , ; . String :

class String { public:
~String();
// destructor
... };

, (~). ( ). . String :

String::~String() {delete str; }

, . - - , . . - , . , str , new String . len, , .

. , , , :

String::~String() {
#ifdef DEBUG
cout << "String() " << len << " " str << "n";
#endif
delete str; }

, , .

o , . -, delete. . ,

#include "String.h"
String search( "rosebud" );
f() { // would not want destructor applied to p
String *p = &search;
// would want destructor applied to p
String *pp = new String( "sleigth" );
// ... body of f() // Sting::String() invoke for pp
delete pp; }

, delete, (.. 0), .

if ( pp != 0 )
delete pp;

, . , , . , new. ,

#include <string.h>
#include <stream.h>
#include <new.h>

struct inBuf { public:
inBuf( char* );
~inBuf();
private: char *st;
int sz;
};

inBuf::inBuf( char *s ) {
st = new char [ sz = strlen(s)+1 ];
strcpy( st, s );
}

inBuf::~inBuf() {
cout<<"inBuf::~inBuf(): " << st <<"n";
delete st;
}

char *pBuf = new char[ sizeof( inBuf ) ];

main() {
inBuf *pb = new (pBuf) inBuf( "free store inBuf #1" );
pb->inBuf::~inBuf();

// explicit destructor call
pb = new (pBuf) inBuf( "free store inBuf #2" );
pb- >inBuf::~inBuf();

// explicit destructor call // ... }

:

inBuf::~inBuf(): free store
inBuf #1 inBuf::~inBuf(): free store
inBuf #2

. ,


pb->inBuf::~inBuf();
// correct

pb->~inBuf();
// error


: «1 2 3 4 5 6 »

,


© . 2006-2008. Created by: Site.bg
: IT | | . | Paparak.bg | | uchenik.com | TRAVEL | | AmAm.bg | . | | AnimeS-bg.com | | | | IT Light | Spodeli.net | - | IDG.BG | Teenproblem.net | - | Fresh-BG.com | Hanovete.com | Bulfleet.com | Mythlands.com | Ohoboho.com | .Com | News24 | Setcom.bg | Atol.bg | Elmaz.com | MobileBulgaria.com