Jump to content

Supraincarcarea Operatorului []


Recommended Posts

//supraincarcarea operatorului []

//a[3] se poate scrie ca *(a+3)


using namespace std;

class vector


	//de tip private

	int v[20];


	void initializeaza(int , int ); //obs ca parametri pot lipsi la declarare, insa NU si TIPUL acestora

	int afiseaza(int );


void vector::initializeaza(int i, int a)


v[i]=a; //pune a pe pozitia i din vector


int vector::afiseaza(int i)


	return v[i];


int main()


	vector w;

	w.initializeaza(4, 8); //se pune valoarea 8 pe pozitia 4

	cout<<w.afiseaza(4)<<" "; //afiseaza ce este pe pozitia 4


	return 0;


//acest operator este binar. a[3] se poate scrie ca *(a+3)

//dorim sa retinem un vector, ca tip class. astfel o functie ca putea intoarce un vector, ceea ce constituie un avantaj. 

//de asemenea, dorim ca data membru sa fir privata si accesul la ea sa aiba loc exclusiv prin intermediul unor metode

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.