Help with complex number types.
-
I am a new user in Visual C++. I have tried calling complex numbers in the usual C++ way. That is by: #include #include using namespace std; int main() { complex a( 3.0, 4.0 ); cout << "Real: " << a.real() << " Image: " << a.imag() << endl; complex b( 6.0, 7.0 ); a = a + b; cout << "Real: " << a.real() << " Image: " << a.imag() << endl; return 0; } This works perfectly in the conventional programming, but if I try to call complex types in class function (the OOP way). The compiler don't recognise this type. Why is this so? How should i try to get around this problem? I have notice a complex template class in VC++ also. Could I use this ? And how should I do it? I am not familiar with template class. :confused:
-
I am a new user in Visual C++. I have tried calling complex numbers in the usual C++ way. That is by: #include #include using namespace std; int main() { complex a( 3.0, 4.0 ); cout << "Real: " << a.real() << " Image: " << a.imag() << endl; complex b( 6.0, 7.0 ); a = a + b; cout << "Real: " << a.real() << " Image: " << a.imag() << endl; return 0; } This works perfectly in the conventional programming, but if I try to call complex types in class function (the OOP way). The compiler don't recognise this type. Why is this so? How should i try to get around this problem? I have notice a complex template class in VC++ also. Could I use this ? And how should I do it? I am not familiar with template class. :confused:
You must to include the math.h header Plus the name od the struct that you need is called
_complex
.. This struct is composed by the real component X abnd imaginary Ystruct _complex num = {8.0, 1.0};
double real = num.x;
double imaginary = num.y;Best Regards Carlos Antollini. www.wanakostudios.com Sonork ID 100.10529 cantollini
-
I am a new user in Visual C++. I have tried calling complex numbers in the usual C++ way. That is by: #include #include using namespace std; int main() { complex a( 3.0, 4.0 ); cout << "Real: " << a.real() << " Image: " << a.imag() << endl; complex b( 6.0, 7.0 ); a = a + b; cout << "Real: " << a.real() << " Image: " << a.imag() << endl; return 0; } This works perfectly in the conventional programming, but if I try to call complex types in class function (the OOP way). The compiler don't recognise this type. Why is this so? How should i try to get around this problem? I have notice a complex template class in VC++ also. Could I use this ? And how should I do it? I am not familiar with template class. :confused:
This works perfectly in the conventional programming, but if I try to call complex types in class function (the OOP way). The compiler don't recognise this type. Could you please elaborate? If the compiler don't recognize the type it means you haven't include the header file <complex>. I have notice a complex template class in VC++ also. Could I use this ? Ehhh, are you kidding? You just used it in your example.
-
This works perfectly in the conventional programming, but if I try to call complex types in class function (the OOP way). The compiler don't recognise this type. Could you please elaborate? If the compiler don't recognize the type it means you haven't include the header file <complex>. I have notice a complex template class in VC++ also. Could I use this ? Ehhh, are you kidding? You just used it in your example.
Well, maybe I didn't quite put it through correctly. I was trying to say that I was able to use that in the conventional way. I was having problem in VC++ 6.0. I was trying to access the complex type in class function. When I tried to put #include . . void trest::tesin(int a) { complex abc; } the complier will report a error with complex, it's not a recognised as a type. I am trying to access this complex type. :omg:
-
You must to include the math.h header Plus the name od the struct that you need is called
_complex
.. This struct is composed by the real component X abnd imaginary Ystruct _complex num = {8.0, 1.0};
double real = num.x;
double imaginary = num.y;Best Regards Carlos Antollini. www.wanakostudios.com Sonork ID 100.10529 cantollini
Thanks for the reply, Carlos. I really appreciate it! I have tried that out. SO any idea how I could manipulate this num with operators? I have tried to do this num = num * 2; This doesn't work.., this is the complier error. error C2676: binary '*' : 'struct _complex' does not define this operator or a conversion to a type acceptable to the predefined operator I need to declare every single operator function? It's there a short cut? :~
-
Well, maybe I didn't quite put it through correctly. I was trying to say that I was able to use that in the conventional way. I was having problem in VC++ 6.0. I was trying to access the complex type in class function. When I tried to put #include . . void trest::tesin(int a) { complex abc; } the complier will report a error with complex, it's not a recognised as a type. I am trying to access this complex type. :omg:
complex (as most standard things) is inside namespace std.
-
complex (as most standard things) is inside namespace std.
Thanks, I really miss that line in the program.I could access this type now in the class function. void trest::tesin(complex a) { complex b; b = b * b; } I am trying to use it in the class function declaration part. The complier scream again for error. rest.h(11) : error C2871: 'std' : does not exist or is not a namespace trest.h(16) : error C2061: syntax error : identifier 'complex' trest.cpp(30) : error C2511: 'tesin' : overloaded member function 'void (class std::complex)' not found in 'trest' trest.h(13) : see declaration of 'trest' X|
-
Thanks, I really miss that line in the program.I could access this type now in the class function. void trest::tesin(complex a) { complex b; b = b * b; } I am trying to use it in the class function declaration part. The complier scream again for error. rest.h(11) : error C2871: 'std' : does not exist or is not a namespace trest.h(16) : error C2061: syntax error : identifier 'complex' trest.cpp(30) : error C2511: 'tesin' : overloaded member function 'void (class std::complex)' not found in 'trest' trest.h(13) : see declaration of 'trest' X|