Namespaces & Static Libs

Started by
8 comments, last by overeasy 13 years, 6 months ago
How to I package my entire static library in one namespace, to avoid conflicts between my Vector2 and Ogre's Vector2?

I want to be able to specify

MyNamespace::Vector2<float>(...);
Ogre::Vector2(...);
Advertisement
When you define your Vector2 do it like this

namespace MyNamespace
{
class Vector2
{
}
}

That way you have to specify the namespace before each one.
Quote:Original post by AndyEsser
When you define your Vector2 do it like this

namespace MyNamespace
{
class Vector2
{
}
}

That way you have to specify the namespace before each one.


Is it proper to do this for all the classes in the library using the same namespace?
It is the only way to do this. You can open a namespace many times, unlike a class which can only de defined once.
Quote:Original post by rip-off
It is the only way to do this. You can open a namespace many times, unlike a class which can only de defined once.


I am now getting errors such as "argument Entity cannot be converted to type Game::Entity" where Game is the name of my namespace. I am getting these from classes within the namespace's classes.

I guess I'm asking if 'using namespace Game' is implicit within the different namespace definitions.

Went from compiling code to 200+ errors by changing my class Vector2d to Vector2 with namespaces o_O
That kind of thing can happen if you're inconsistent with defining things inside the namespace. Make sure that both your headers and source file contents are inside the namespace.
Quote:Original post by no such user
That kind of thing can happen if you're inconsistent with defining things inside the namespace. Make sure that both your headers and source file contents are inside the namespace.


All my classes and implementations are now wrapped within namespace Game{} brackets, not including imports. Next possible reason?
I fixed all the errors by moving my prototyping into the namespace declaration
Quote:Original post by overeasy
Quote:Original post by no such user
That kind of thing can happen if you're inconsistent with defining things inside the namespace. Make sure that both your headers and source file contents are inside the namespace.


All my classes and implementations are now wrapped within namespace Game{} brackets, not including imports. Next possible reason?


As the old saying goes. There are only two things hard about programming: cache invalidation, naming things and off by one errors.
I would have to say using "Game" as a name is pretty poor.
Quote:Original post by CmpDev
Quote:Original post by overeasy
Quote:Original post by no such user
That kind of thing can happen if you're inconsistent with defining things inside the namespace. Make sure that both your headers and source file contents are inside the namespace.


All my classes and implementations are now wrapped within namespace Game{} brackets, not including imports. Next possible reason?


As the old saying goes. There are only two things hard about programming: cache invalidation, naming things and off by one errors.
I would have to say using "Game" as a name is pretty poor.


Sue me

This topic is closed to new replies.

Advertisement