Jump to content
  • Advertisement
Sign in to follow this  

[C++ / Irrlitch] Namespace problem

This topic is 4061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I'm still learning things every day w/ C++ and GCC. I'm using Irrlitch, and I've been working with some of the examples. Variables were initially preceded by their respective namespace info but I want to declare the namespace. However I am running in to a problem, after I declare the namespaces it interferes with the std namespace, saying that string type isn't defined, and I get the following compile error... 17 C:\Dev-Cpp\main.cpp expected constructor, destructor, or type conversion before '*' token Any thoughts?
#include <cstdlib>
#include <iostream>
#include <vector>
#include <irrlicht.h>

using namespace std;

using namespace irr::core;
using namespace irr::io;
using namespace irr::video;
using namespace irr::scene;
using namespace irr::gui;

IrrlichtDevice 		*IrrDevice;
IVideoDriver	*IrrDriver;
ISceneManager	*IrrSceneManager;

Share this post

Link to post
Share on other sites
This situation is exactly what namespaces are intended to solve. That is, libraries that have the same names. In this case, there's a class named "string" in both std and irrlicht::core. So then when you declare something as type "string", the compiler has no idea which you're referring to.

You'll need to expicitly tell the compiler which you want, by declaring the object as "irrlicht::core::string" or "std::string". It sounds like you don't want to do this, but you don't have much choice for classes with the same name. Fortunately, you only need to do it in this case. Other classes with unique names don't need to be preceded by the namespace.

Share this post

Link to post
Share on other sites
using <namespace> is generally considered a Bad Idea, and your example showed exactly why.

Of course, having to type irr::video::whatever might be a wee bit verbose, but then you could do something like this:
namespace iv = irr::video;

and then you only have to prefix everything with iv::

Alternatively, include the irr namespaces, but don't do it with the std namespace.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!