Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with complex number types.

Help with complex number types.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oRion
    wrote on last edited by
    #1

    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:

    C M 2 Replies Last reply
    0
    • O oRion

      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:

      C Offline
      C Offline
      Carlos Antollini
      wrote on last edited by
      #2

      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 Y

      struct _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

      O 1 Reply Last reply
      0
      • O oRion

        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:

        M Offline
        M Offline
        Mike Nordell
        wrote on last edited by
        #3

        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.

        O 1 Reply Last reply
        0
        • M Mike Nordell

          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.

          O Offline
          O Offline
          oRion
          wrote on last edited by
          #4

          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:

          M 1 Reply Last reply
          0
          • C Carlos Antollini

            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 Y

            struct _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

            O Offline
            O Offline
            oRion
            wrote on last edited by
            #5

            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? :~

            1 Reply Last reply
            0
            • O oRion

              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:

              M Offline
              M Offline
              Mike Nordell
              wrote on last edited by
              #6

              complex (as most standard things) is inside namespace std.

              O 1 Reply Last reply
              0
              • M Mike Nordell

                complex (as most standard things) is inside namespace std.

                O Offline
                O Offline
                oRion
                wrote on last edited by
                #7

                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|

                O 1 Reply Last reply
                0
                • O oRion

                  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|

                  O Offline
                  O Offline
                  oRion
                  wrote on last edited by
                  #8

                  Hey, got my problems solved! Just a few missing lines from the original codes. Thanks for all your help guys! Cheers, Danny :rolleyes:

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups