473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Operator not found for the type

I tried to define an overloader for the operator <<. My source

code is great except the stupid compiler doesn't get it. :)

std::ostream& Particle::operator<< (Particle& part) {

std::ostream* ost = NULL;

(*ost) << "diffusion particle";

return (*ost); }
The error message is
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'Particle' (or there is no acceptable conversion)
What did i do unsmartly?

--
Vänligen Kerstin Viltersten
(The Cool Giraffe)
Mar 1 '07 #1
2 2165
The Cool Giraffe wrote:
I tried to define an overloader for the operator <<. My source

code is great except the stupid compiler doesn't get it. :)

std::ostream& Particle::operator<< (Particle& part) {

std::ostream* ost = NULL;

(*ost) << "diffusion particle";

return (*ost); }
The error message is
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'Particle' (or there is no acceptable conversion)
What did i do unsmartly?
Don't make the operator a member function, use

std::ostream& operator<<( std::ostream&, const Particle& ) {..}

--
Ian Collins.
Mar 1 '07 #2
Ian Collins wrote:
The Cool Giraffe wrote:
>I tried to define an overloader for the operator <<. My source

code is great except the stupid compiler doesn't get it. :)

std::ostream& Particle::operator<< (Particle& part) {

std::ostream* ost = NULL;

(*ost) << "diffusion particle";

return (*ost); }
The error message is
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'Particle' (or there is no acceptable conversion)
What did i do unsmartly?
Don't make the operator a member function, use

std::ostream& operator<<( std::ostream&, const Particle& ) {..}
It's not the source of the compile error, but he also is dereferencing
a null pointer for unexplained reasons.
Mar 1 '07 #3

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

Similar topics

5
by: bsaucer | last post by:
I am creating a class with operator overloads. It makes references to another class I've created, but do not wish to modify. I try to overload an operator having arguments having the other class...
7
by: Richard Hayden | last post by:
Hi, I have the following code for example: /**********************************/ #include <iostream> class C1 { public:
9
by: Gyro | last post by:
Dear All! Why there is no operator= for any type? I trying: typedef float mtx; operator=(mtx a, mtx b) { } compiler compaints that error: "operator=" must be a member function
11
by: Shaun | last post by:
Hi, I'm trying to overload the divide operator in python for basic arithmetic. eg. 10/2 ... no classes involved. I am attempting to redefine operator.__div__ as follows: # my divide...
20
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...
2
by: michael.rygh | last post by:
This is just one of the sources for a project that deals with a library. I am having problems, here is the errors. all these.. i belive it has something to do with it needs a subscript? but i'm...
8
by: David Williams | last post by:
Hi all, I have a templated Vector3D class which holds (x,y,z) components as the specified type. I quite often wish to cast a Vector3D holding ints into a Vector3D holding floats and vice versa....
2
by: linq936 | last post by:
Hi, I have this piece code, struct TriStr { MyString str1; MyString str2; MyString str3; TriStr(MyString s1, MyString s2, MyString s3){ this->str1 = s1;
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
5
by: krzysztof.konopko | last post by:
I cannot compile the code which defines a std::map type consisting of built in types and operator<< overload for std::map::value_type. See the code below - I attach a full example. Note: if I...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.