-
February 14th, 2012, 01:04 AM
#1
[RESOLVED] at a loss with overloading opperators
Code:
friend ostream& operator<<(ostream& ostm, const Mixed& m);
friend istream& operator>>(istream& istm, Mixed& m);
friend bool operator<(const Mixed& lhs, const Mixed& rhs);
friend bool operator>(const Mixed& lhs, const Mixed& rhs);
friend bool operator<=(const Mixed& lhs, const Mixed& rhs);
friend bool operator>=(const Mixed& lhs, const Mixed& rhs);
friend bool operator==(const Mixed& lhs, const Mixed& rhs);
friend bool operator!=(const Mixed& lhs, const Mixed& rhs);
friend Mixed operator+(const Mixed& lhs, const Mixed& rhs);
friend Mixed operator-(const Mixed& lhs, const Mixed& rhs);
friend Mixed operator*(const Mixed& lhs, const Mixed& rhs);
friend Mixed operator/(const Mixed& lhs, const Mixed& rhs);
friend Mixed operator++(Mixed& m, int);
friend Mixed operator++(Mixed& m);
friend Mixed operator--(Mixed& m, int);
friend Mixed operator--(Mixed& m);
i keep getting errors with all 6 with bool when i dont comment them out in the driver if you need my .h and 2 .cpp files let me know! thank you!
Code:
1>main.obj : error LNK2019: unresolved external symbol "bool __cdecl operator<(class Mixed const &,class Mixed const &)" (??M@YA_NABVMixed@@0@Z) referenced in function _main
1>c:\users\austin\documents\visual studio 2010\Projects\finalff\Debug\finalff.exe : fatal error LNK1120: 1 unresolved externals
more info
Code:
// demonstrate comparison overloads
if (x < y) cout << "(x < y) is TRUE\n";
if (x > y) cout << "(x > y) is TRUE\n";
if (x <= y) cout << "(x <= y) is TRUE\n";
if (x >= y) cout << "(x >= y) is TRUE\n";
if (x == y) cout << "(x == y) is TRUE\n";
if (x != y) cout << "(x != y) is TRUE\n";
Last edited by austinm6; February 14th, 2012 at 01:42 AM.
-
February 14th, 2012, 02:00 AM
#2
Re: at a loss with overloading opperators
Perhaps you forgot to compile and link the source file containing their definitions, or perhaps their definitions don't match the declarations.
-
February 14th, 2012, 02:13 AM
#3
Re: at a loss with overloading opperators
Originally Posted by laserlight
Perhaps you forgot to compile and link the source file containing their definitions, or perhaps their definitions don't match the declarations.
Everything is there and looks good to the eye, atleast for a novice like me.
@laser - sent a message let me know! thanks!
-
February 14th, 2012, 04:01 AM
#4
Re: at a loss with overloading opperators
Originally Posted by austinm6
Everything is there and looks good to the eye, atleast for a novice like me.
Perhaps it looks good to your eye but not for linker...
And we do NOT see the implementation of
Code:
friend bool operator<(const Mixed& lhs, const Mixed& rhs);
either.
Victor Nijegorodov
-
February 14th, 2012, 04:44 AM
#5
Re: at a loss with overloading opperators
Originally Posted by austinm6
Everything is there and looks good to the eye, atleast for a novice like me.
The linker doesn't lie. You are missing that implementation that the linker is looking for.The key word is implementation. Just a declaration is not enough.
As to "your eye" -- does everything look good in this example?
Code:
void foo();
int main()
{
foo();
}
This compiles, but the linker will give you the exact same error. So what is missing here? It is the implementation of the foo() function.
Even though you see a declaration of foo(), all that declaration does is make the compiler happy when you call the function. It is the linker that now needs to know where the "guts" of foo() exists. It isn't found, so the linker gives you an error.
This in a nutshell is what the linker is telling you. Also since C++ allows function overloading, possibly you believe you've implemented your operator function, but you didn't really implement it.
Example:
Code:
void foo();
void foo(int);
int main()
{
foo(6);
}
void foo()
{ }
Again, this compiles, and it looks like it should work, but look which foo() you're calling -- you're calling the one that takes an int argument, and that version of foo(int) was not implemented. Only the no-argument of foo was implemented.
So either you never implemented them, or you didn't compile the module(s) where the implementations exist (and give these modules to the linker via your project).
Regards,
Paul McKenzie
Last edited by Paul McKenzie; February 14th, 2012 at 04:47 AM.
-
February 14th, 2012, 06:35 AM
#6
Re: at a loss with overloading opperators
Originally Posted by Paul McKenzie
The linker doesn't lie. You are missing that implementation that the linker is looking for.The key word is implementation. Just a declaration is not enough.
As to "your eye" -- does everything look good in this example?
Code:
void foo();
int main()
{
foo();
}
This compiles, but the linker will give you the exact same error. So what is missing here? It is the implementation of the foo() function.
Even though you see a declaration of foo(), all that declaration does is make the compiler happy when you call the function. It is the linker that now needs to know where the "guts" of foo() exists. It isn't found, so the linker gives you an error.
This in a nutshell is what the linker is telling you. Also since C++ allows function overloading, possibly you believe you've implemented your operator function, but you didn't really implement it.
Example:
Code:
void foo();
void foo(int);
int main()
{
foo(6);
}
void foo()
{ }
Again, this compiles, and it looks like it should work, but look which foo() you're calling -- you're calling the one that takes an int argument, and that version of foo(int) was not implemented. Only the no-argument of foo was implemented.
So either you never implemented them, or you didn't compile the module(s) where the implementations exist (and give these modules to the linker via your project).
Regards,
Paul McKenzie
Just finished thanks to you!!! thank you so much, your advice really helped! 6:35 A.M time for zZzZ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|