| | |
Error message help?
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
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.
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::endl; #include "Complex.h" int main() { Complex x(2, 3), y(4, 5), z; x.printComplex(); cout << " + "; y.printComplex(); cout << " = "; x.add(y); x.printComplex(); cout << '\n'; x.setComplexNumber(10, 1); //reset Real y.setComplexNumber(11, 5); //reset Imaginery x.printComplex(); cout << " - "; y.printComplex(); cout << " = "; x.subtract(y); x.printComplex(); cout << '\n'; x.equal(y); cout << endl; return 0; }
C++ Syntax (Toggle Plain Text)
#ifndef Complex_H #define Complex_H class Complex { public: Complex(double = 0.0, double = 0.0); //default constructor Complex Complex::add(Complex &); Complex Complex::subtract(Complex &); void printComplex(void); void setComplexNumber(double, double); Complex Complex::equal(Complex &x); private: double realPart; double imagineryPart; } #endif
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; #include <Complex.h> Complex::Complex(double real, double imaginery) { setComplexNumber(real, imaginery); } void Complex::add(Complex &) { realPart += a.realPart; imagineryPart =+ a.imagineryPart; } void Complex::subtract(Complex &) { realPart -= s.realPart; imagineryPart -= s.realPart; } void Complex::printComplex(void) { cout << '(' << realPart << ", " << imagineryPart << ')'; } void setComplexNumber(double rp, dounle ip) { realPart = rp; imagineryPart = ip; } bool Complex::equal(Complex &x) { return ((realPart == x.realPart) && (imagineryPart == x.imagineryPart)); }
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.
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
Hi, thanks for reading my message. I've changed my code a bit and I get it to compile but the math is wrong.
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.
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; using std::endl; #include "Complex.h" int main() { Complex x; Complex y( 3, 4); Complex z( 6, 2); cout << "x: "; x.printComplex(); cout << "\ny: "; y.printComplex(); cout << "\nz: "; z.printComplex(); x = y + z; cout << "\n\nx = y + z:\n"; x.printComplex(); cout << " = "; y.printComplex(); cout << " + "; z.printComplex(); x = y - z; cout << "\n\nx = y - z:\n"; x.printComplex(); cout << " = "; y.printComplex(); cout << " - "; z.printComplex(); cout << endl; return 0; }// end main
C++ Syntax (Toggle Plain Text)
#include <iostream> using std::cout; #include "Complex.h" Complex::Complex(double realPart, double imagineryPart) : real( realPart ), imaginery( imagineryPart) { //empty body } //addition Complex Complex::operator+( Complex &operand2) { return Complex( real + operand2.realPart, imaginery + operand2.imagineryPart ); }//end //subtraction Complex Complex::operator-( Complex &operand2) { return Complex( real - operand2.realPart, imaginery - operand2.imagineryPart ); }//end //display in form (a, b) void Complex::printComplex() const { cout << '(' << realPart << ", " << imagineryPart << ')'; } //equal or not bool Complex::equal(Complex &x) { return ((realPart == x.realPart) && (imagineryPart == x.imagineryPart)); }
C++ Syntax (Toggle Plain Text)
#ifndef Complex_H #define Complex_H class Complex { public: Complex(double = 0.0, double = 0.0); //default constructor Complex Complex::operator+( Complex &); Complex Complex::operator-( Complex &); void printComplex() const; bool Complex::equal(Complex &x); private: double realPart; double imagineryPart; double real; double imaginery; }; #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.
![]() |
Similar Threads
- Toshiba IDE1 error message (Windows NT / 2000 / XP)
- MERGED: Hardware/Driver Problems-Error Message (Windows 95 / 98 / Me)
- wupdater.exe error message (Web Browsers)
- Please help with DLL error message! (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Creating own datatypes
- Next Thread: "Craps", Game Help
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets





