[try Beta version]
Not logged in

 
Overloading operators Question

Feb 15, 2015 at 7:34pm
I'm not sure if anyone came across this and probably very rare to come across. But i was thinking if you have a class specifically a vector type or a array type class and you need to overload the cout << and cin >> operators. For instance you want to have user input chars into array and output what they wrote. Then you want to cout lets say the size of the array. What can i do for it to cout what i want?

For example



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Class a
Public:
void size();
operator <<
operator >>
private:





  int main;

 a test, test2;
cin>>test;
cout<< test;
cout<< test2.size();  This wont work since i overload the << operator to output       array contents
Last edited on Feb 15, 2015 at 7:35pm
Feb 15, 2015 at 9:42pm
You should not overload the operators for this. The behavior you want is specific to your use case and does not belong in generic operators.
Feb 17, 2015 at 12:12am
but can you do multiple overload operators ? and usually i would just cout in the size function.
Feb 17, 2015 at 6:37pm
I don't understand your question.
Topic archived. No new replies allowed.