Jump to content

Recommended Posts

Posted
#include<iostream>

using namespace std;

class vector

{

	int v[100]; //de tip private

public:

int &operator[](int i);

};

int &vector::operator[](int i) //fara & nu am fi putut face atribuiri: a[o pozitie] ia valoarea x.

{

	return v[i]; //am acces la v pentru ca operator[] este metoda a clasei vector

}

int main()

{

	vector a;

	a[1]=5;

	cout<<a[1]<<" ";

	a[3]=10;

	cout<<a[3]<<" ";

	system("PAUSE");

	return 0;

}

  • Upvote 1
  • 4 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • 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.