• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

overloading << operator with variable args

is it possible to overload the insertion operator << with variable number of arguments.It would be very
helpful if someone explains with an example.the MS VC++ compiler does not even allow the declation but why??
thanx
kalyan
0
kalv
Asked:
kalv
  • 4
1 Solution
 
alexoCommented:
No, you cannot.
The reason is that when you overload operators, you can only change the functionality and the types of the arguments, *not* the number of arguments, precedence or associativity.

In other words, the built-in operator<<() takes one argument, so all overloaded operators must follow that convention.
0
 
kalvAuthor Commented:
is it possible to write a member function to overload it,i know to do it as a friend.
0
 
kalvAuthor Commented:
Alexo,
  if i write it as a friend it takes two args,one for the loperand and the other
for the roperand.but how do you do it as a member function?
0
 
kalvAuthor Commented:
please explain me with an example to write it as a member function
0
 
kalvAuthor Commented:
iam ready to give 10 points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now