• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • 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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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