Thread: complex class imp?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    82

    complex class imp?

    Hi,

    I'm only a c programmer and have only had brushes with c++ and OO, so I came across this nice diagram in wikipedia which is generated from given c++ and would like to get it to compile.

    However, it requires a complex class implementation, which I don't understand too well. I like to thing of a class merely as a set of structs with functions also included. That's my highly uninformed opinion.

    But I don't want to discuss what a class is, merely how to get a complex number one into that program. I jogged off to the GNU GMP, even if it's overkill, I thought it would at least have what I'm looking for. I had trouble finding a complex class implementation in there, so I dropped it.

    Can anybody set me on the right path here, sorry that I'm so hazy on the terminology.

    May be I can just build the class myself ... there are examples I can follow .. but all I would do is generate the struct (two floats) and include the constructor and destructor ... and that's all?

    Maybe some knows of a link to this problem? Cheers!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I have to say, I never used complex number.
    I'm pretty sure, however, it is supported natively in C++. You'll have to include the header file <complex>, and the class is named std::complex.
    This source code seems to be pre-standard C++, where you could for instance include iostream.h, and it would not be loaded into the std namespace.

    So I guess the code works if you add #include <complex> and "using std::complex;"

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The standard complex class is likely a template, so you may need to do something like:
    Code:
    complex<double> var;
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    thanks EVOEx and matsp,

    those bits of advice helped me get there in the end, though I've definitely unsure of my feet in c++.

    This source code seems to be pre-standard C++
    Haha! its very C yes! Now you know why chose it! Heigh up, I said, some C++ I understand!

    I have to say, I never used complex number.
    the joys that await you ...

    Many thanks both.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. Problem from texbook
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-26-2002, 04:55 AM