Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Not understanding why I got these compiler errors

Author
Message
Citokre
5
Years of Service
User Offline
Joined: 26th Mar 2014
Location: Centreville, VA
Posted: 30th Mar 2014 17:27
So for my assignment, I'm supposed to write a program that draws an Octagon using functions. It's supposed to be at the center of the screen, and have a width and height of 40. I used basic math to figure out the dbLines (simple enough), and I declared the x#'s and y#'s as constants because they'll be re-used in the next assignment to make a pattern of 4 octagons.

The code is done, but the compiler keeps throwing me the errors:

C2365: 'y1': redefinition; previous definition was 'function' in line 18

C2664: 'dbLine' : cannot convert parameter 2 from 'double (__cdecl *)(double)' to 'int' in line 59

C2664: 'dbLine' : cannot convert parameter 4 from 'double (__cdecl *)(double)' to 'int' in line 66

I looked them up, but didn't quite understand what the MSDN page for them showed. Basically, as for the const int y1 I don't see where it had a "previous definition" and on the C2664s I don't see how it's changing from "double" to "int" (as I understand what it's saying)

Here's a paste of my source, any help would be greatly appreciated:
http://fpaste.org/89969/96189567/
The Tall Man
5
Years of Service
User Offline
Joined: 16th Nov 2013
Location: Earth
Posted: 1st Apr 2014 02:49 Edited at: 1st Apr 2014 02:53
In your global variables, you're setting them to values using uninitialized variables centerX and centerY.

Also, it looks like what you're meaning to do is to use #defines instead of global variables (global variables are probably frowned upon by your professor anyway). Move the centerX and centerY integer declarations to the DarkGDK() function. And use these #defines in the global space as you did the const ints:



...and so on.

Keep in mind that a #define is used to replace code text with the NAME you're defining, at compile-time. So you don't need to predefine or initialize the centerX and centerY variables before your #defines.

I would have called the RADIUS #defines (radius) X and Y, but then I saw in your code that wouldn't be correct. So name them whatever is more appropriate with what you're doing. The reason I recommend #defining them rather than making them the constants 10 and 20 that you have, is because you're repeating them throughout your definitions.

I don't think your pattern will be an octagon with width and height of 40 though. If it isn't, you may want to consider using plain ints instead of #defines or const ints for your x and y point values, and generate their values using a little math equation rather than hard-coding them in there. An equation that should work is the parametric form of a circle. Then your only #defines would be the OCTAGON_WIDTH and OCTAGON_HEIGHT of 40 and OCTAGON_SIDES of 8 (to be used in the parametric circle equation).
Citokre
5
Years of Service
User Offline
Joined: 26th Mar 2014
Location: Centreville, VA
Posted: 1st Apr 2014 05:28
Thanks for the input. I'll definitely file that away for later as a way to do stuff like this. It took me a while but I figured it out and got the assignment completed, it just took the mods some time to approve the post. lol

Thanks again for the help/input!

Login to post a reply

Server time is: 2019-08-24 09:44:43
Your offset time is: 2019-08-24 09:44:43