Thread: Class Name Conflicts....?

  1. #1
    Registered User dug's Avatar
    Join Date
    Jun 2003

    Class Name Conflicts....?


    so here's a classic.... i've got a mathematics library, and its got a class called 'Point3d' and it represents a point in 3d space, and i have other code in the library that depends on it, for instance, Vertex3d etc.

    so i get my mate to write a library that does some other 3dish type things... and he's got a class called 'Point3d' that is different from mine.... and it's in his namespace 'davelib'.

    now, i write a piece of code that needs to use BOTH Point3d classes, one from my library and own from davelib... BUT we end up with compilation errors, 'Point3d is ambiguous', which it obviously is...

    so the question is: is there a way to resolve this someway without renaming the classes in one of the libraries...? or are we in for a real pain in the ........?

    thanks in advance
    "take the long road.... and walk it."

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    In the code that uses both classes, make sure that you don't put using namespace davelib;. Instead, whenever you need to use his class, just put davelib::Point3d.

    Of course, it would be even better if your code was also in a namespace, then you could always specify which one you were referring to. As it is, there are still some instances where the compiler might get confused, like functions with the same name in each library that take Point3d objects as arguments, but they are pretty rare.

  3. #3
    Registered User dug's Avatar
    Join Date
    Jun 2003
    it was the combination of:

    using namespace ashlib;

    that was the problem....

    nice one, thanks.
    "take the long road.... and walk it."

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    You could also coordinate your effort and write one common Point3D class.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User dug's Avatar
    Join Date
    Jun 2003
    you're a genius...

    but uh, this is obviously a very simplified example of what we're doing.... and i thought i would generalise the case and the problem so that others would be able to learn from it quite easily, without being swamped in detail.

    but yes, obviously that would be a sensible solution.... but not practical in EVERY situation.
    "take the long road.... and walk it."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM