Solved

overloading << operator with variable args

Posted on 1998-07-30
5
197 Views
Last Modified: 2010-04-02
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
Comment
Question by:kalv
  • 4
5 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 10 total points
ID: 1169022
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
 

Author Comment

by:kalv
ID: 1169023
is it possible to write a member function to overload it,i know to do it as a friend.
0
 

Author Comment

by:kalv
ID: 1169024
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
 

Author Comment

by:kalv
ID: 1169025
please explain me with an example to write it as a member function
0
 

Author Comment

by:kalv
ID: 1169026
iam ready to give 10 points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question