473,663 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

one overload question

Hi,

I have this program, compiling is passed, but when i wanted to get the
executable file(g++ -o output input.o), it fails.

Who can lead me where the error is?

Thanks,
Hunter
===
#include <iostream>
class Rational {

public:

Rational( int par1 = 0, int par2 = 1 ): n( par1 ), d( par2 ) {}

void printRational( );
int getN() const { return n; }

int getD() const { return d; }

void setN( int par ) { n = par; }

void setD( int par ) { d = par; }

public:

friend const Rational& operator * ( const Rational& par1,
const Rational& par2 );

private:

int n, d;
};

const Rational& operator * ( const Rational& rat1, const Rational& rat2 )
{

// I know this solution is bad and there's a correct one, I just want to
try what Scott Mayers says.
static Rational result;

result.setN( rat1.getN() * rat2.getN() ) ;
result.setD( rat1.getD() * rat2.getD() ) ;

return result;
}

void Rational::print Rational() {

std::cout << "the N is: " << n << "the D is: " << d << std::endl;

}
int main()
{

Rational rat1( 2, 3 ), rat2( 4, 5 );

Rational result = rat1 * rat2;

result.printRat ional();

return 0;

}
LocalRef.o(.tex t+0xba):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char, std::char_trait s<char>
&)' LocalRef.o(.tex t+0xe0):LocalRe f.cpp: undefined reference to `std::cout'
LocalRef.o(.tex t+0xe5):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>&, char const*)' LocalRef.o(.tex t+0xee):LocalRe f.cpp: undefined reference to
`std::ostream:: operator<<(int) '
LocalRef.o(.tex t+0xf7):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>&, char const*)'

LocalRef.o(.tex t+0x100):LocalR ef.cpp: undefined reference to
`std::ostream:: operator<<(int) '
LocalRef.o(.tex t+0x109):LocalR ef.cpp: undefined reference to
`std::ostream:: operator<<(std: :ostream& (*)(std::ostrea m&))'
LocalRef.o(.tex t+0x1a8):LocalR ef.cpp: undefined reference to
`std::ios_base: :Init::Init()'
LocalRef.o(.tex t+0x1c7):LocalR ef.cpp: undefined reference to
`std::ios_base: :Init::~Init()'


Jul 22 '05 #1
6 1679
Hunter Hou wrote:
Hi,

I have this program, compiling is passed, but when i wanted to get the
executable file(g++ -o output input.o), it fails.

Who can lead me where the error is?

Why do you think this is an "overload question"? Anyway, it looks to me
as if your linker doesn't find the symbols of the standard library. Are
you sure you used g++ for linking, not gcc, and that you linked your
code using the same g++ version you compiled it with?

Jul 22 '05 #2
Rolf Magnus wrote:
Hunter Hou wrote:

Hi,

I have this program, compiling is passed, but when i wanted to get the
executable file(g++ -o output input.o), it fails.

Who can lead me where the error is?


Why do you think this is an "overload question"? Anyway, it looks to me
as if your linker doesn't find the symbols of the standard library. Are
you sure you used g++ for linking, not gcc, and that you linked your
code using the same g++ version you compiled it with?


In fact, I don't know if this is really caused by overload.
I've been using g++ of mingw and never run into such a confusing problem.
Jul 22 '05 #3
"Hunter Hou" <hy***@lucent.c om> wrote in message
news:ca******** @netnews.proxy. lucent.com...
Hi,

I have this program, compiling is passed, but when i wanted to get the
executable file(g++ -o output input.o), it fails.

Who can lead me where the error is?

Thanks,
Hunter
=== <snip>
LocalRef.o(.tex t+0xba):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::endl<char,
std::char_trait s<char> >(std::basic_os tream<char, std::char_trait s<char>
&)'

LocalRef.o(.tex t+0xe0):LocalRe f.cpp: undefined reference to `std::cout'
LocalRef.o(.tex t+0xe5):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>
&, char const*)'

LocalRef.o(.tex t+0xee):LocalRe f.cpp: undefined reference to
`std::ostream:: operator<<(int) '
LocalRef.o(.tex t+0xf7):LocalRe f.cpp: undefined reference to
`std::basic_ost ream<char, std::char_trait s<char> >& std::operator<<
<std::char_trai ts<char> >(std::basic_os tream<char, std::char_trait s<char>
&, char const*)'

LocalRef.o(.tex t+0x100):LocalR ef.cpp: undefined reference to
`std::ostream:: operator<<(int) '
LocalRef.o(.tex t+0x109):LocalR ef.cpp: undefined reference to
`std::ostream:: operator<<(std: :ostream& (*)(std::ostrea m&))'
LocalRef.o(.tex t+0x1a8):LocalR ef.cpp: undefined reference to
`std::ios_base: :Init::Init()'
LocalRef.o(.tex t+0x1c7):LocalR ef.cpp: undefined reference to
`std::ios_base: :Init::~Init()'


I had this problem before, but didn't resolve yet.
Try this simple application and see if it compile / links too:

#include <iostream>

using namespace std;

int main()
{
cout << "Hello world!\n" << endl;
return 0;
}

--
Elias
Jul 22 '05 #4
Hunter Hou wrote:
Rolf Magnus wrote:
Hunter Hou wrote:

Hi,

I have this program, compiling is passed, but when i wanted to get
the executable file(g++ -o output input.o), it fails.

Who can lead me where the error is?


Why do you think this is an "overload question"? Anyway, it looks to
me as if your linker doesn't find the symbols of the standard
library. Are you sure you used g++ for linking, not gcc, and that you
linked your code using the same g++ version you compiled it with?


In fact, I don't know if this is really caused by overload.
I've been using g++ of mingw and never run into such a confusing
problem.


The linker error message reports things like endl, cout and the stream
operators (actually everything from the standard library that you're
using) being missing. There seems to be no connection to the fact that
you're overloading operator*.

Jul 22 '05 #5
lallous wrote:

I had this problem before, but didn't resolve yet.
Try this simple application and see if it compile / links too:

#include <iostream>

using namespace std;

int main()
{
cout << "Hello world!\n" << endl;
return 0;
}

--
Elias


My test.cpp is as exactly same as yours, it works.That's why the above
error is confusing me.

Hunter
Jul 22 '05 #6

"Hunter Hou" <hy***@lucent.c om> wrote in message
news:ca******** @netnews.proxy. lucent.com...
lallous wrote:

I had this problem before, but didn't resolve yet.
Try this simple application and see if it compile / links too:

#include <iostream>

using namespace std;

int main()
{
cout << "Hello world!\n" << endl;
return 0;
}

--
Elias


My test.cpp is as exactly same as yours, it works.That's why the above
error is confusing me.


OK well start taking the obvious troubleshooting steps. Gradually cut out
code from the program that doesn't work, until you have a hello world
program. When it starts working again you know that the last thing you
removed was the problem.

Personally I don't think there is anything wrong with your code, I would
expect there is something wrong with the way you are compiling and linking
your program or something wrong with the way you have installed your
compiler.

John
Jul 22 '05 #7

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

Similar topics

5
2064
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 type, but none of the new class type. However it does return a type of the new class. The compiler tells me that at least one parameter must be of the containing type. Is there a way to do this? The other class hos no reference to this new class. Is...
9
1609
by: Mario Charest | last post by:
.. Hi, It's possible to overload the operator, but I wonder if it's possible to somehow overload and so forth. My goal would be to switch from static array declaration into something totaly dynamic with minimal change in the code. The following code
13
1665
by: Tony Johansson | last post by:
Hello! I just wonder if it's possible to overload a method only by having a different return type. //Tony
17
2504
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: public static bool operator !=(MyType x, MyType y) { return !(x == y); } That way the == operator handles everything, and extra comparing logic isn't
10
2210
by: shachar | last post by:
hi all. can i OverLoad Operators - such as Exclamation Mark "!" ? how?
3
8293
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
1
1800
by: bhavin | last post by:
it is possible to overload new and delete operator but why is it needed to overload new and delete this question is asked by my professor so please any body reply to this question,also explain in a simple way with a simple e.g
5
3478
by: richard.parker | last post by:
Hello, I need to overload operator new with affecting the system libraries. Has anyone done this? I've got 2 static libraries and application source code where the operator needs to be overloaded, but I need to link with the system libraries (frameworks) and I DO NOT want my overloads to be mapped to them. I'm working with some code that is currently working on Win32 but also needs to work on the Mac. Under windows this is very...
1
1341
by: v4vijayakumar | last post by:
When (at which phase of the software development) the decision would usually be taken to overload operators? Will you first design with functions and then move these functionalities to overloaded operators? When we can surely say, we need a functor here, or, predicate here, for example? Hope, this is not off-topic.
0
8436
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
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8771
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
7371
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...
1
6186
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
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
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1757
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.