Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redefinition of int right error using winbgim library

I have a problem with making a program that uses winbgim.h header file. It is a simple program that makes just one simple circle. I am currently learning about winbgim and graphics.h libraries. I downloaded it, I downloaded the library and included it in Codeblocks following this and it works properly.

But when I try to use it, another code pops out and on the 302nd line it stands "error: redefinition of "int right". I am making this in a console file in Codeblocks IDE.

Can anyone help? Here is my code:

#include <iostream>
#include <winbgim.h>
#include <cstdlib>

using namespace std;

int main()
{
   int gdriver = 9;
   int gmode = 2;
   initgraph(&gdriver,&gmode, "");
   setbkcolor(WHITE);
   setcolor(BLACK);
   cleardevice();
   circle(320,240,180);
   getch();
   closegraph();
   return 0;
}
like image 884
Adem Dinarević Avatar asked Sep 17 '14 13:09

Adem Dinarević


2 Answers

I don't know whether it suits this forum or not but I just wanted to tell (the world) something. I recently decided to try out WinBGIm library, so I downloaded the package and after setting up all the compiler and linker settings, ran my simple "Hello World" Code. But I got the following message from my compiler (MinGW, CodeBlocks IDE).

d:\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\graphics.h|302|error: redefinition of 'int right'|

d:\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\graphics.h|302|error: 'int right' previously declared here|

||=== Build finished: 2 errors, 0 warnings ===|

After having googled the problem I found out nothing (If you don't count a suggestion to use CodeBlocks-EP as a Solution). As I was taking a look at the header files, I found the problem (yeah!!!) The problem was with the function printimage. The original declaration was

//The original declaration. Note that there are two "right" variables

void printimage(
    const char* title=NULL, 
    double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
    int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
    bool active=true, HWND hwnd=NULL
    );

So what I did is that, I simply changed one of the "right" (the later former one) variable to "top". That's it.

//The corrected code
void printimage(
    const char* title=NULL, 
    double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
    int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
    bool active=true, HWND hwnd=NULL
    );
like image 166
Puneet Shrivas Avatar answered Nov 20 '22 20:11

Puneet Shrivas


I did the same thing as @Puneet suggested, just change the name of one of the variables named "right".

The thing that I want to add is that you can't change the name within codeblocks (at least I couldn't do it, the changes were ignored). So I suggest you save your code file/s, close the IDE, and open the "graphics.h" file with a text editor, change the name, save, and you are all set.

You can find your MinGW directory by opening a new codeblocks project, right click in the <iostream> and select something like open file, which will open the header in a new codeblocks "tab", right click the tab and click open containing folder. Thats it.

like image 1
J3STER Avatar answered Nov 20 '22 19:11

J3STER