Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

overloading << operator with variable args

Posted on 1998-07-30
5
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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