Solved

overloading << operator with variable args

Posted on 1998-07-30
5
189 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now