473,702 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why? eval.cpp:25: error: no match for 'operator+' in '*result_plus + *car(iter)'

Hello all,

I've got a problem on operator overloading, I don't know what's wrong
with my code.
Can anyone kindly tell me what's the problem is?
Thanks

//this is the error message I've got
eval.cpp:25: error: no match for 'operator+' in '*result_plus +
*car(iter)'

//here is my code
//Cell.cpp overload operator+
Cell* operator+ (const Cell &a, const Cell &b) const {
if (a.is_cons()){
eval(&a);
}
if (b.is_cons()){
eval(&b);
}
if (a.is_int() && b.is_int()){
int result_i = a.get_int() + b.get_int();
return new IntCell(result_ i);
}
if (a.is_int() && b.is_double()){
double result_d = a.get_int() + b.get_double();
return new DoubleCell(resu lt_d);
}
if (a.is_double() && b.is_int()){
double result_d = a.get_double() + b.get_int();
return new DoubleCell(resu lt_d);
}
if (a.is_double() && b.is_double()){
double result_d = a.get_double() + b.get_double();
return new DoubleCell(resu lt_d);
}
if (a.is_string() && b.is_string()){
string result_s = a.get_string() + b.get_string();
const char* result_c = result_s.c_str( );
return new StringCell(resu lt_c);
}
else {
cout << "Error: the expression is illegal" <<endl;
exit(0);
}
}

//main.cpp
Cell* result_plus = make_int(0);
iter = cdr(iter);
while (iter !=NULL){
result_plus = *result_plus +
*car(iter);
iter = cdr(iter);
}
return result_plus;

May 5 '06 #1
6 5486
ho********@gmai l.com wrote:
I've got a problem on operator overloading, I don't know what's wrong
with my code.
Can anyone kindly tell me what's the problem is?
Not enough information.
//this is the error message I've got
eval.cpp:25: error: no match for 'operator+' in '*result_plus +
*car(iter)'
[...]
//main.cpp
Cell* result_plus = make_int(0);
iter = cdr(iter);
while (iter !=NULL){
result_plus = *result_plus +
*car(iter);
iter = cdr(iter);
}
return result_plus;


What does "car(iter)" evalutate to?

V
--
Please remove capital As from my address when replying by mail
May 5 '06 #2
* ho********@gmai l.com:
Hello all,

I've got a problem on operator overloading, I don't know what's wrong
with my code.
Can anyone kindly tell me what's the problem is?
Thanks

//this is the error message I've got
eval.cpp:25: error: no match for 'operator+' in '*result_plus +
*car(iter)'

//here is my code
//Cell.cpp overload operator+
Cell* operator+ (const Cell &a, const Cell &b) const {


Try this program:

struct Cell
{
Cell* operator+ (const Cell &a, const Cell &b) const
{
return this;
}
};

int main(){}

If your compiler doesn't tell you directly what's wrong, then you should
be able to figure it out nonetheless.

I mean, this is a pretty strong hint. ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 5 '06 #3
>What does "car(iter)" evalutate to?

car(iter) will return the Cell pointer of the its car

sorry that I may not explain it in details
but the following links will have better explaination
http://en.wikipedia.org/wiki/Cons
http://en.wikipedia.org/wiki/Car_and_cdr

so what I am try to do is
there are 3 cells called a, b and c
and I can use the "+" in this way
a = b + c;

Thank you.

May 5 '06 #4
ho********@gmai l.com wrote:
What does "car(iter)" evalutate to?


car(iter) will return the Cell pointer of the its car

sorry that I may not explain it in details
but the following links will have better explaination
http://en.wikipedia.org/wiki/Cons
http://en.wikipedia.org/wiki/Car_and_cdr

so what I am try to do is
there are 3 cells called a, b and c
and I can use the "+" in this way
a = b + c;


What book do you use to learn about operator overloading? What's
it say about operators as member functions versus non-members?

V
--
Please remove capital As from my address when replying by mail
May 5 '06 #5
I use Thinking in C++ as reference book
but it said there are no differences between member function and
non-members operator overloading

Victor Bazarov wrote:
ho********@gmai l.com wrote:
What does "car(iter)" evalutate to?


car(iter) will return the Cell pointer of the its car

sorry that I may not explain it in details
but the following links will have better explaination
http://en.wikipedia.org/wiki/Cons
http://en.wikipedia.org/wiki/Car_and_cdr

so what I am try to do is
there are 3 cells called a, b and c
and I can use the "+" in this way
a = b + c;


What book do you use to learn about operator overloading? What's
it say about operators as member functions versus non-members?

V
--
Please remove capital As from my address when replying by mail


May 5 '06 #6
ho********@gmai l.com wrote:
Victor Bazarov wrote:
ho********@gm ail.com wrote:
What does "car(iter)" evalutate to?

car(iter) will return the Cell pointer of the its car

sorry that I may not explain it in details
but the following links will have better explaination
http://en.wikipedia.org/wiki/Cons
http://en.wikipedia.org/wiki/Car_and_cdr

so what I am try to do is
there are 3 cells called a, b and c
and I can use the "+" in this way
a = b + c;


What book do you use to learn about operator overloading? What's
it say about operators as member functions versus non-members?

I use Thinking in C++ as reference book
but it said there are no differences between member function and
non-members operator overloading

Please don't top-post.

Victor suggested you look up operators as member functions versus
non-members, as well as overloading, two different topics.

Your book should explain when it is and isn't appropriate to use either
form.

--
Ian Collins.
May 5 '06 #7

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

Similar topics

18
2367
by: Joe Laughlin | last post by:
(file and class names changed to protect the innocent) g++ -Wall -c file.cpp: In member function `std::string Some_Class::get_member(const std::string&) const': file.cpp:46: passing `const std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >' as `this' argument of `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator(const _Key&) ' discards qualifiers
12
2524
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an argument. I was hoping to create a map<int, const char*that would be used in the showError member function of the TExceptionHandler class where the key (int) would be the error code and const char* the message printed out to the console. My question...
4
2465
by: Gary Wessle | last post by:
Hi I have a vector<stringwhich holds numbers, I need to loop and printout those numbers + a value as doubles . typedef vector<string>::const_iterator vs_itr; for(vs_itr i=vect.begin(); i!=vect.end(); ++i){ cout << *i << '\t' << strtod(*i)+val << '\n';
1
3371
by: girays | last post by:
I have a template class which name is EntityRepository and when I compile this class I get no error. But when I use this class in a main method I get LNK2019 linking error. std::map object is used in EntityRepository template class. You can see the EntityRepository.h and EntityRepository.cpp and main method below: //EntityRepository.h #pragma once #ifndef ENTITYREPOSITORY_H #define ENTITYREPOSITORY_H
4
1955
by: Jon Rea | last post by:
I have the following code that works on Visual C++ 2005 and on GCC. bool VectorContains( const std::vector<int>& vect, int value ) { std::vector<int>::const_iterator iter; for( iter = vect.begin(); iter != vect.end(); iter++ ) { if( *iter == value ) { return true;
3
4886
nabh4u
by: nabh4u | last post by:
i have a program where i have to use gale shapley's algorithm to match companies and persons. i create preference lists for both companies and persons. i am almost done but i am not getting the output. i should get the output with the persons who were hired and the companies who hire them. please help me as i have a very short deadline to submit this program. /----match.h--------------------------------------------------------------/ ...
4
2004
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local): template<typename T> class Row<T> : public std::vector<T> {}; template<typename...
6
2543
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be appreciated. What I'm trying to accomplish is using boost::lexical_cast to cast a vector of strings to a string. The compiler I'm using is MSVC++ 2005 Express Edition. The gc++
6
3259
by: APEJMAN | last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result I post the code here I dont wanne bother you, but if any one of you have time to read my program I appriciate it. the program suppose to print a message on the screen #include <iostream> #include <string>
0
8738
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9086
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7829
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5907
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.