I've been asked to overload the insertion operator. What exactly is
the insertion operator in C++, and how would one overload it? I think
that in C I could overload the "+" operator like so:
double operator+ ( char* left
, char* right)
{
// some code here
}
Could I do that in C++ too? Or is there a different way to do it?
---Kevin Simonson
"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_ 3 4662
Alf P. Steinbach wrote:
* kv******@hotmail.com:
>I've been asked to overload the insertion operator. What exactly is the insertion operator in C++
There is no insertion operator in C++, but, stretching the English
language, "<<" is used as an insertion operator for streams, and some
authors call that the C++ "insertion operator".
>, and how would one overload it? I think that in C I could overload the "+" operator like so:
double operator+ ( char* left , char* right) { // some code here }
As far as I know even C99 doesn't support operator overloading.
lcc-win32, a C compiler, supports operator overloading as an extension.
On 2007-08-27 07:32, Alf P. Steinbach wrote:
* kv******@hotmail.com:
>I've been asked to overload the insertion operator. What exactly is the insertion operator in C++
There is no insertion operator in C++, but, stretching the English
language, "<<" is used as an insertion operator for streams, and some
authors call that the C++ "insertion operator".
>>, and how would one overload it? I think that in C I could overload the "+" operator like so:
double operator+ ( char* left , char* right) { // some code here }
As far as I know even C99 doesn't support operator overloading.
In C++ you can't overload on pointer types.
To clarify, at least one of the operands of the operator has to be a
user defined type, i.e. you cannot change or add the operators of
built-in types.
--
Erik Wikström This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ceo |
last post by:
Hi there,
I'm trying to overload insertion (<<) and extraction (>>) operators and
the program yields output I didn't expect. Could someone please clarify
what's wrong with my program.
Thanks,...
|
by: ryan.fairchild |
last post by:
I have a problem I am trying to create a MyInt class to hanlde very
large ints. Its for a class, therefore I can only do what the teach
tells me. I want to be able to overload the insertion...
|
by: jois.de.vivre |
last post by:
Hi, I'm having some trouble overloading the << operator. I have the
following, very simple code:
#include <iostream>
using namespace std;
class test
{
private:
int val;
|
by: Patrick Guio |
last post by:
Dear all,
I have some problem with insertion operator together with namespace.
I have a header file foo.h containing declaration of classes, typedefs and
insertion operators for the typedefs in...
|
by: acheron05 |
last post by:
Hi,
I've been writing a program for another school assignment but I am
having trouble working out how to overload the < and << operators. The
program is designed to read data from a file, create...
|
by: raan |
last post by:
What I am trying to achieve here is depicted in the small program
below.
// Wrapit.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <map>
#include...
|
by: EM.Bateman |
last post by:
Working on Visual Studio .Net I've implemented a class:
#ifndef CONTRIBUTOR_H
#define CONTRIBUTOR_H
enum Gender {male=1, female, unk};
#include <iostream>
#include <iomanip>
#include...
|
by: davoxol |
last post by:
Hi, I have a problem using the insertion overloading. I defined it this way:
friend ostream& operator<< (ostream& os, Base & base);
I have to get specific output depending on the type of...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |