4 Replies - 651 Views - Last Post: 04 January 2009 - 10:37 AM Rate Topic: -----

#1 DAQStudios  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 10-November 08

Conflicting Libraries

Posted 04 January 2009 - 09:36 AM

Hey everyone. I'm having a slight issue here. I'm working on a poker game that can be played over the internet. I've worked out pretty much all the details and issues except one. To make the interface look clean and attractive, I'm using this library:
#include <allegro.h>


However, to send the information over the internet, I'm using this library:
#include <wininet.h>


Apparently, both of these libraries define a Bitmap so there is a confliction in programming and my Dev C++ starts yelling at me. Any suggestions how to fix this? Can I tell the program to disregard a library for a time and not for elsewhere? I had an idea using if/then statements which might work, but it'll get really messy. Is there something better I can try?

This post has been edited by DAQStudios: 04 January 2009 - 09:37 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Conflicting Libraries

#2 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: Conflicting Libraries

Posted 04 January 2009 - 10:09 AM

Try adding this line of code before your bitmap section of code
using namespace allegro;

This should make it clear to the compiler which library to use for bitmap manipulation.

Another option would be to specify each line of code that uses an Allegro function with
Allegro::<function>

This post has been edited by Pwn: 04 January 2009 - 10:10 AM

Was This Post Helpful? 1
  • +
  • -

#3 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 844
  • View blog
  • Posts: 2,334
  • Joined: 20-August 07

Re: Conflicting Libraries

Posted 04 January 2009 - 10:16 AM

if the issue is one of name clashes, then using namespace is probably what caused it in the first place. If both libraries are tucked away within their own namespaces, then the solution is to make sure those names remain safely away from the global namespace (remove any lines from your code which start with 'using namespace' - especially if those lines exist at global scope).
Instead, Whenever you need to reference a name from within the allegro namespace, you can prefix that name with allegro::, or be more careful about where you place your using declarations - so that the effect is limited to as narrow scope as possible. With that approach, you shouldn't experience name clashes between names which exist in separate namespaces.

This post has been edited by Bench: 04 January 2009 - 10:25 AM

Was This Post Helpful? 1
  • +
  • -

#4 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: Conflicting Libraries

Posted 04 January 2009 - 10:28 AM

if you use the namespace in your code, end it when you are finished with it with an "end using" statement. Then you are only using it at that point that you need it.
Was This Post Helpful? 1
  • +
  • -

#5 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 844
  • View blog
  • Posts: 2,334
  • Joined: 20-August 07

Re: Conflicting Libraries

Posted 04 January 2009 - 10:37 AM

View PostPwn, on 4 Jan, 2009 - 05:28 PM, said:

if you use the namespace in your code, end it when you are finished with it with an "end using" statement. Then you are only using it at that point that you need it.

That may be a compiler-specific extension which you're referring to, because there's no such keyword as end in standard C++. Once you have added 'using namespace' somewhere, then every name within that namespace is brought into the current scope (Whether that be global scope, class scope, function scope or anything else). You cannot 'undo' a using namespace with standard C++. The nearest you can do is to wrap the code where your using declaration appears with a pair of curly parenthesis, creating unnamed scope - eg.
#include <iostream>

int main()
{
    {
        using namespace std;
        cout << "hello";    // ok
    }

    cout << "world";        // error
} 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1