473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

multiply defined operator

Hi I keep having problems with trying to overload the << operator,
the compiler will not let me define it.

the code looks like

#ifndef __MYARRAY_H__
#define __MYARRAY_H__
#include <iostream>
..
..
..
..
};

ostream & operator<<(ostream &o, MyArray& m)
{
return m(o);
}

#endif

It wont work if I put it inside or out of the #endif

The error that the compiler keeps giving me is this.

ld: fatal: symbol `operator<<(std::basic_ostream<char,
std::char_traits<char> >&, MyArray&)' is multiply defined:
(file MyArrayMain.o and file MyArray.o);
ld: fatal: File processing errors. No output written to myarray
collect2: ld returned 1 exit status

Please help.
thanks a lot
Jul 19 '05 #1
3 4127

"Brett Irving" <ba*****@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi I keep having problems with trying to overload the << operator,
the compiler will not let me define it.

the code looks like

#ifndef __MYARRAY_H__
#define __MYARRAY_H__
#include <iostream>
.
.
.
.
};

ostream & operator<<(ostream &o, MyArray& m)


Should be

inline ostream & operator<<(ostream &o, MyArray& m)

Also you are ignoring the issue of const, you should write

inline ostream & operator<<(ostream &o, const MyArray& m)

because you don't change a MyArray when you output it. Although making this
change will probably mean that you have to stop ignoring the issue of const
in the declaration of MyArray as well. Look on it as a good oppurtunity to
learn about const.

john
Jul 19 '05 #2
Brett Irving wrote:
#ifndef __MYARRAY_H__
#define __MYARRAY_H__


C++ standard specifically reserves macros with two sequential
underscores for use by the implementation. In most cases, there is no
problem, but if you want your code to be portable... You will propably
do just fine if you write only:

#ifndef MYARRAY_H
#define MYARRAY_H

Jul 19 '05 #3
Thanks Heaps

"John Harrison" <jo*************@hotmail.com> wrote in message news:<bd************@ID-196037.news.dfncis.de>...
"Brett Irving" <ba*****@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi I keep having problems with trying to overload the << operator,
the compiler will not let me define it.

the code looks like

#ifndef __MYARRAY_H__
#define __MYARRAY_H__
#include <iostream>
.
.
.
.
};

ostream & operator<<(ostream &o, MyArray& m)


Should be

inline ostream & operator<<(ostream &o, MyArray& m)

Also you are ignoring the issue of const, you should write

inline ostream & operator<<(ostream &o, const MyArray& m)

because you don't change a MyArray when you output it. Although making this
change will probably mean that you have to stop ignoring the issue of const
in the declaration of MyArray as well. Look on it as a good oppurtunity to
learn about const.

john

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Red | last post by:
what is the best way to multiply a tuple or list by a given value exp. multiply (4, 5) by 2 => (8, 10) cheers jr
15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
3
by: Dave | last post by:
Hello all, Please consider this code: #ifndef FOO_INCLUDED #define FOO_INCLUDED // File: foo.h class foo {
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
4
by: trint | last post by:
Why do we have to use decimal.multiply to multiply two intgers? I just want to multiply these two values: int oneThousand = 1000; int watCHTimer1 = value from a textbox; Thanks, Trint
6
by: John | last post by:
I have 5 native static libraries that are being compiled in Visual Studio 2005 with the /MDd C Runtime option. I have 2 CLR DLLs (all managed code) in Visual Studio 2005 and the /MDd C Runtime...
8
by: gavinstone007 | last post by:
Who can solve this? Wrte a class number which represents all numbers. Implement member functions to carry out the following arithmetic operations on class instances, add- which returns an object...
3
by: ADS7328 | last post by:
Dear everybody, I trying to compile an aplication and i have got the following error during linking phase: ld: fatal: symbol `K_MultiHandler_c::~K_MultiHandler_c #Nvariant 1()' is...
1
by: Gavin Chen | last post by:
Hello: I tried to install Tk800.015 on SunOS 4.1.4 with perl 5.6.2. At "make test" time, I got the error message as below: collect2: ld returned 2 exit status ld:...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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....
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.