Error message help?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 2
Reputation: deedlit21 is an unknown quantity at this point 
Solved Threads: 0
deedlit21 deedlit21 is offline Offline
Newbie Poster

Error message help?

 
0
  #1
Sep 26th, 2004
Hello,

when i try to compile this program (it has three parts) I receive an error message that confuses me. Below are the code and error message.

  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. #include "Complex.h"
  7.  
  8. int main()
  9. {
  10. Complex x(2, 3), y(4, 5), z;
  11.  
  12. x.printComplex();
  13. cout << " + ";
  14. y.printComplex();
  15. cout << " = ";
  16. x.add(y);
  17. x.printComplex();
  18.  
  19. cout << '\n';
  20. x.setComplexNumber(10, 1); //reset Real
  21. y.setComplexNumber(11, 5); //reset Imaginery
  22. x.printComplex();
  23. cout << " - ";
  24. y.printComplex();
  25. cout << " = ";
  26. x.subtract(y);
  27. x.printComplex();
  28.  
  29. cout << '\n';
  30. x.equal(y);
  31. cout << endl;
  32.  
  33. return 0;
  34. }

  1. #ifndef Complex_H
  2. #define Complex_H
  3.  
  4. class Complex {
  5. public:
  6. Complex(double = 0.0, double = 0.0); //default constructor
  7. Complex Complex::add(Complex &);
  8. Complex Complex::subtract(Complex &);
  9. void printComplex(void);
  10. void setComplexNumber(double, double);
  11. Complex Complex::equal(Complex &x);
  12. private:
  13. double realPart;
  14. double imagineryPart;
  15. }
  16.  
  17. #endif

  1. #include <iostream>
  2.  
  3. using std::cout;
  4.  
  5. #include <Complex.h>
  6.  
  7. Complex::Complex(double real, double imaginery)
  8. { setComplexNumber(real, imaginery); }
  9.  
  10. void Complex::add(Complex &)
  11. {
  12. realPart += a.realPart;
  13. imagineryPart =+ a.imagineryPart;
  14. }
  15.  
  16. void Complex::subtract(Complex &)
  17. {
  18. realPart -= s.realPart;
  19. imagineryPart -= s.realPart;
  20. }
  21.  
  22. void Complex::printComplex(void)
  23. { cout << '(' << realPart << ", " << imagineryPart << ')'; }
  24.  
  25. void setComplexNumber(double rp, dounle ip)
  26. {
  27. realPart = rp;
  28. imagineryPart = ip;
  29. }
  30.  
  31. bool Complex::equal(Complex &x) {
  32. return ((realPart == x.realPart) &&
  33. (imagineryPart == x.imagineryPart));
  34. }

The error msg says:
C:\IS20\Complex Classes\Complex.cpp(16) : error C2556: 'void __thiscall Complex::add(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::add(class Complex &)'
c:\is20\complex classes\complex.h(10) : see declaration of 'add'
C:\IS20\Complex Classes\Complex.cpp(16) : error C2371: 'add' : redefinition; different basic types
c:\is20\complex classes\complex.h(10) : see declaration of 'add'
C:\IS20\Complex Classes\Complex.cpp(17) : error C2065: 'a' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(17) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(18) : error C2228: left of '.imagineryPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(22) : error C2556: 'void __thiscall Complex::subtract(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::subtract(class Complex &)'
c:\is20\complex classes\complex.h(11) : see declaration of 'subtract'
C:\IS20\Complex Classes\Complex.cpp(22) : error C2371: 'subtract' : redefinition; different basic types
c:\is20\complex classes\complex.h(11) : see declaration of 'subtract'
C:\IS20\Complex Classes\Complex.cpp(23) : error C2065: 's' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(23) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(24) : error C2228: left of '.realPart' must have class/struct/union type
C:\IS20\Complex Classes\Complex.cpp(30) : error C2061: syntax error : identifier 'dounle'
C:\IS20\Complex Classes\Complex.cpp(33) : error C2065: 'ip' : undeclared identifier
C:\IS20\Complex Classes\Complex.cpp(36) : error C2556: 'bool __thiscall Complex::equal(class Complex &)' : overloaded function differs only by return type from 'class Complex __thiscall Complex::equal(class Complex &)'
c:\is20\complex classes\complex.h(14) : see declaration of 'equal'
C:\IS20\Complex Classes\Complex.cpp(36) : error C2371: 'equal' : redefinition; different basic types
c:\is20\complex classes\complex.h(14) : see declaration of 'equal'


I do not understand what that means. Can anyone help me? Thanks so much, I really appreciate it a lot.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: deedlit21 is an unknown quantity at this point 
Solved Threads: 0
deedlit21 deedlit21 is offline Offline
Newbie Poster

Re: Error message help?

 
0
  #2
Sep 26th, 2004
Hi, thanks for reading my message. I've changed my code a bit and I get it to compile but the math is wrong.

  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. #include "Complex.h"
  7.  
  8. int main()
  9. {
  10. Complex x;
  11. Complex y( 3, 4);
  12. Complex z( 6, 2);
  13.  
  14. cout << "x: ";
  15. x.printComplex();
  16. cout << "\ny: ";
  17. y.printComplex();
  18. cout << "\nz: ";
  19. z.printComplex();
  20.  
  21. x = y + z;
  22. cout << "\n\nx = y + z:\n";
  23. x.printComplex();
  24. cout << " = ";
  25. y.printComplex();
  26. cout << " + ";
  27. z.printComplex();
  28.  
  29. x = y - z;
  30. cout << "\n\nx = y - z:\n";
  31. x.printComplex();
  32. cout << " = ";
  33. y.printComplex();
  34. cout << " - ";
  35. z.printComplex();
  36. cout << endl;
  37.  
  38.  
  39. return 0;
  40. }// end main

  1. #include <iostream>
  2.  
  3. using std::cout;
  4.  
  5. #include "Complex.h"
  6.  
  7. Complex::Complex(double realPart, double imagineryPart)
  8. : real( realPart ),
  9. imaginery( imagineryPart)
  10. {
  11. //empty body
  12. }
  13.  
  14. //addition
  15. Complex Complex::operator+( Complex &operand2)
  16. {
  17. return Complex( real + operand2.realPart,
  18. imaginery + operand2.imagineryPart );
  19. }//end
  20.  
  21. //subtraction
  22. Complex Complex::operator-( Complex &operand2)
  23. {
  24. return Complex( real - operand2.realPart,
  25. imaginery - operand2.imagineryPart );
  26. }//end
  27.  
  28. //display in form (a, b)
  29. void Complex::printComplex() const
  30. {
  31. cout << '(' << realPart << ", " << imagineryPart << ')';
  32. }
  33.  
  34. //equal or not
  35. bool Complex::equal(Complex &x) {
  36. return ((realPart == x.realPart) &&
  37. (imagineryPart == x.imagineryPart));
  38. }

  1. #ifndef Complex_H
  2. #define Complex_H
  3.  
  4. class Complex {
  5. public:
  6. Complex(double = 0.0, double = 0.0); //default constructor
  7. Complex Complex::operator+( Complex &);
  8. Complex Complex::operator-( Complex &);
  9. void printComplex() const;
  10. bool Complex::equal(Complex &x);
  11. private:
  12. double realPart;
  13. double imagineryPart;
  14. double real;
  15. double imaginery;
  16. };
  17.  
  18. #endif

Could you please look this over and tell me what myself and the debugger are messing up?

Also, how do I make use of the equal function so that it doesn't just sit there?

Thanks for your help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC