Logo by HPDZ - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Did you know ? you can use LaTex inside Postings on fractalforums.com!
 
*
Welcome, Guest. Please login or register. November 29, 2025, 06:39:18 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Help with complex header file in c++?  (Read 1202 times)
0 Members and 1 Guest are viewing this topic.
stigomaster
Guest
« on: September 06, 2009, 01:26:30 PM »

I am currently trying to write a buddhabrot program, and I would very much like to use the standard library <complex> header. So I include it, I use namespace std, and still these lines produce errors.
Code:
    complex cc(0.0, 0.0);
    complex zz(0.0, 0.0);
    
    complex tl = complex(0);  // Top left
    complex br = complex(0);  // Bottom right

    switch SCREEN_W {
        case 1024:
            tl = complex(-2.36, -1.26);
            br = complex(1, 1.26);
            break;
        case 1280:
            tl = complex(-2.5, -1.25);
            br = complex(1.5, 1.25);
            break;
        case 800:
            tl = complex(-2.36, -1.26);
            br = complex(1, 1.26);
            break;
    }

The errors I receive are:
41 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp missing template arguments before "cc"
41 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected `;' before "cc"

Please give help to a young nerd on the ridge of despair.
« Last Edit: September 06, 2009, 01:29:06 PM by stigomaster, Reason: Had to add error description » Logged
lycium
Fractal Supremo
*****
Posts: 1158



WWW
« Reply #1 on: September 06, 2009, 01:34:02 PM »

it would be good if you could report the error msg and the line on which it occurs  afro
Logged

stigomaster
Guest
« Reply #2 on: September 06, 2009, 01:42:22 PM »

Well, I did right after I posted the initial question, see OP. The error messages are identical for every line containing "complex(_,_)" declarations. Additionally, the lines immediately following those lines gets an error message as well:
47 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected primary-expression before "double"
47 C:\Dev-Cpp\Prosjekter\Buddhabrot\Main.cpp expected `;' before "double"

I am using Dev-C++ 4.9.9.2 and the Allegro game library.
Logged
lycium
Fractal Supremo
*****
Posts: 1158



WWW
« Reply #3 on: September 06, 2009, 03:03:52 PM »

the complex class is templated, so you'd like to define a type:

typedef complex<double> complex_d;

then you can use eg.

complex_d a(0, 0), b(0, sqrt(2)); // etc...
Logged

stigomaster
Guest
« Reply #4 on: September 06, 2009, 06:59:34 PM »

Code:
    complex_d tl (0);  // Top left
    complex_d br (0);  // Bottom right
   
    double redch  [SCREEN_W, SCREEN_H] = 0.0;  // Arrays for color channels
    double greench[SCREEN_W, SCREEN_H] = 0.0;
    double bluech [SCREEN_W, SCREEN_H] = 0.0;

The typedef surely removed a great deal of the error messages, but these lines following the complex declarations still report
Code:
expected primary-expression before "double"
expected `;' before "double"

Why can't the compiler just do whatever I want it to?
Logged
lycium
Fractal Supremo
*****
Posts: 1158



WWW
« Reply #5 on: September 10, 2009, 02:22:24 PM »

there are a few things to note here:

1. trying to assign a variable to an array won't work, you'd need a for-loop to assign each of the elements individually (or a memset call).
2. it's not a good idea to separate the R, G and B components into seperate arrays, rather make a "colour" class containing the 3 elements.
3. using double precision floating point for your components is "a little" excessive tongue stuck out
4. rather index directly into a single-dimensional array instead of using 2d arrays.


Why can't the compiler just do whatever I want it to?
most people need psychoanalysts to work out what they actually, exactly want in a given situation wink computers can only do as they're told of course, and there's not a lot of room for interpretation!
Logged

HPDZ
Iterator
*
Posts: 157


WWW
« Reply #6 on: September 21, 2009, 11:14:00 PM »

Why can't the compiler just do whatever I want it to?

Microsoft, I hear, was working on a psychic compiler. They abandoned it and focused their efforts on incorporating psychic techology into their Office products. So far they have only done it with outline numbering in Word, and initial results have been abysmal.

Logged

Zoom deeply.
www.hpdz.net
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Amazing Hybrid Complex Triplex (complex coloring scheme) Images Showcase (Rate My Fractal) M Benesi 0 4198 Last post June 28, 2010, 02:47:56 AM
by M Benesi
save fractal parameters in png file Mandelbulb 3d mondaymorninglunatic 2 4080 Last post March 02, 2011, 10:14:16 AM
by mondaymorninglunatic
Save 3d file Mandelbulb 3d scheven_architect 5 4050 Last post May 07, 2011, 07:42:38 AM
by Don Whitaker
is it a cat? starter file 3 Mandelbulb3D Gallery cKleinhuis 0 1175 Last post November 01, 2012, 06:09:53 PM
by cKleinhuis
Importing param file UltraFractal Stonevoice 4 6468 Last post June 21, 2014, 10:25:30 PM
by Sockratease

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.277 seconds with 24 queries. (Pretty URLs adds 0.01s, 2q)