Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

Namespaces & Static Libs

Started by overeasy Sep 29, 2010 at 3:48 PM 8 replies 1.1k views
Original Post
overeasy
overeasy
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(...);
Ogre::Vector2(...);
AndyEsser
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.
overeasy
overeasy
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?
rip-off
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.
overeasy
overeasy
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
no such user
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.
overeasy
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?
overeasy
overeasy
I fixed all the errors by moving my prototyping into the namespace declaration
CmpDev
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.
overeasy
overeasy
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.