473,408 Members | 1,830 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,408 software developers and data experts.

Operator Overloading Error

I am receiving a strange error, one I have never seen before.

error LNK2019: unresolved external symbol "public: __thiscall Complex::~Complex(void)" (??1Complex@@QAE@XZ) referenced in function _main

I also receive a fatal error:

fatal error LNK1120: 1 unresolved externals

If I do: #include "Complex.h" that takes care of the top error, however I still receive the fatal error.

I'm not sure what could be causing these. Any ideas??

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<iostream>
  3. using namespace std;
  4. //#include "Complex.h"
  5. class Complex
  6. {
  7. public:
  8.     Complex(double =0.0, double= 0.0);
  9.     ~Complex();
  10.     Complex operator+(Complex &);
  11.     Complex operator*(Complex &);
  12.     void print ();
  13. private:
  14.     double real;
  15.     double imaginary;
  16. };
  17. Complex::Complex(double r_port, double i_port):real(r_port),imaginary(i_port)
  18. {
  19.  
  20. }
  21. Complex Complex::operator+(Complex &operand2)
  22. {
  23.     return (Complex(real+operand2.real,imaginary+operand2.imaginary));
  24. }
  25. Complex Complex::operator*(Complex &operand2)
  26. {
  27.     return (Complex(real*operand2.real,imaginary*operand2.imaginary));
  28. }
  29. void Complex::print()
  30. {
  31.     cout<<'('<<real<<','<<imaginary<<')';
  32. }
  33. void main ()
  34. {
  35.     double real1,imag1,real2,imag2;
  36.     cout<<"Enter your first real number: "<<endl;
  37.     cin>>real1;
  38.     cout<<"Enter your first imaginary number: "<<endl;
  39.     cin>>imag1;
  40.     cout<<"Enter your second real number: "<<endl;
  41.     cin>>real2;
  42.     cout<<"Enter your second imaginary number: "<<endl;
  43.     cin>>imag2;
  44. //    Complex x;
  45.     Complex x(real1,imag1);
  46.     Complex y(real2,imag2);
  47.     cout<<"x: ";
  48.     x.print();
  49.     cout<<endl<<"y: ";
  50.     y.print();
  51. //    cout<<endl<<"z: ";
  52. //    z.print();
  53. }
  54.  
  55.  
Thanks,
J
Jul 12 '07 #1
10 1519
JosAH
11,448 Expert 8TB
As far as I can see you forgot to define your ~Complex() dtor but you did declare
it; you must define it then.

kind regards,

Jos
Jul 12 '07 #2
As far as I can see you forgot to define your ~Complex() dtor but you did declare
it; you must define it then.

kind regards,

Jos

Awesome Jos. I am looking at my past programs and in the book, and nowhere did I (or the author) define their destructor. That did it though.


Thanks,

J
Jul 12 '07 #3
Found the problem....program is working.


Thanks to those who took a look and offered advice.

J
Jul 12 '07 #4
Darryl
86
Awesome Jos. I am looking at my past programs and in the book, and nowhere did I (or the author) define their destructor. That did it though.


Thanks,

J
You didn't define it BUT you did declare it. If you don't declare it, one will be created for you automatically, but since you declared one, you must define it also.
Jul 12 '07 #5
You didn't define it BUT you did declare it. If you don't declare it, one will be created for you automatically, but since you declared one, you must define it also.

Cool. Like I said, I've never had to define one in any of the other programs I've wiritten.

Thanks for taking a look Darryl.


J
Jul 13 '07 #6
The overloading problem has been solved. I missed in the assignment the part around using set and get functions. The set function is where I would actually enter the numbers from the user? And the get function would.....send those values to the print function??

I get confused about the set and get functions.

J
Jul 13 '07 #7
Darryl
86
Cool. Like I said, I've never had to define one in any of the other programs I've wiritten.

Thanks for taking a look Darryl.


J
I'll bet you did...You can't show me 1 piece of code that declares a destructor and didn't define it also and still compiles. Maybe you defined it inline and didn't realize it like:

Expand|Select|Wrap|Line Numbers
  1. class foo
  2. {
  3. public:
  4.     // ~foo();  - not defined
  5.      ~foo(){}  // ok
  6. };
  7.  
The braces there defines it.
Jul 13 '07 #8
hi dear
u forget to defined ur ~complex(); detroyed function/
Jul 14 '07 #9
You're right Daryl, that is how I defined the destructor.

My next question is, I need to implement set and get functions. I missed that little line in the problem. Does the set function just initialize the 2 sets to 0,0 and the get function take in the info of the 2 sets? The set and get functions still confuse me for some reason.


J
Jul 16 '07 #10
Problem solved.


Thanks,
J
Jul 16 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tim Milstead | last post by:
(CODE AT END OF POST) I have got some code for finding memory leaks that works well with: new() and needs to be extended to work with new
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
5
by: James Angi | last post by:
I have a question on operator overloading that I can't find an answer to in several guides (even google has failed me). I'm currently making my way through several C++ guides, trying to become...
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
11
by: jakester | last post by:
I am using Visual C++ 2007 to build the code below. I keep getting linkage error. Could someone please tell me what I am doing wrong? The code works until I start using namespace for my objects. ...
16
by: EM.Bateman | last post by:
Working on Visual Studio .Net I've implemented a class: #ifndef CONTRIBUTOR_H #define CONTRIBUTOR_H enum Gender {male=1, female, unk}; #include <iostream> #include <iomanip> #include...
5
by: ashu | last post by:
i have studied this example of overloading operator, but i don`t know exactly what happened in code .kindly explain me: #include <iostream> using namespace std; const int SIZE = 3; class...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
15
by: =?Utf-8?B?VkIgRGV2ZWxvcGVy?= | last post by:
Overloading of the unary ++ operator in vb.net is not working. It show error: Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
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.