Reputation: 48
I am an engineering student and not a very strong programmer. One of my assignments includes creating a VR program using openGL. I've been given a template (that I really don't want to re-write) that uses the gmtl headers extensively. The assignment requires implementing some sixense position tracker hardware in the simulation, however, the headers for the sixense hardware and gmtl both have a number of classes (Plane, Line, etc.) with the same names. Is there anything I can do to use both that doesn't involve going through lots of code and renaming things?
Upvotes: 0
Views: 1258
Reputation: 14622
As commenters have stated, they are in different namespaces so you should be fine, as long as you fully qualify your namespaces, which is good practice too:
namespace foo { int value; }
namespace bar { int value; }
int main()
{
foo::value = 1;
bar::value = 2;
return 0;
}
You only run into trouble if you use using namespace
recklessly:
namespace foo { int value; }
namespace bar { int value; }
using namespace foo;
using namespace bar;
int main()
{
value = 1; // which value is this???
return 0;
}
In practice, if you have well-structured, modular code, it will be very rare to have to use two classes with the same name in the same source file, and usually the classes are doing the same thing, which means you can isolate the verbose, fully-qualified type names in a "conversion" source file, and continue to use using namespace
in your other source files.
Upvotes: 2