C++重载[]数组操作符

#include
#include

using namespace std;

class CharPair{
public:
	CharPair(){
		
	}
	CharPair(char first, char second): first(first), second(second){
		
	}
	
	char &operator[](int index);
	
private:  
	char first;
	char second;
};

int main(){
	CharPair a;
	a[1] = 'A';
	a[2] = 'B';
	cout<>a[1]>>a[2];
 	cout<<"New latters;"<

你可能感兴趣的:(C++重载[]数组操作符)