Jump to content
  • Advertisement
Sign in to follow this  
skydave

define class in global namespace from within another namespace

This topic is 3678 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

Hi, I would like to define a class in global namespace from within a application namespace like so:
namespace test
{
    namespace ??? // heres my problem: I want to 'junp out' of
                  // the current namespace into the global namespace
    {
        class GlobalClass
        {
        };
    }    
}

GlobalClass c; // should be possible because GlobalClass has been
               // defined in global namespace


Is this somehow possible? Thanks in advance, David

Share this post


Link to post
Share on other sites
Advertisement
I don't understand the question. You can open and close a particular namespace any number of times, so you can just do this:

namespace test
{
// declarations
}

class GlobalClass
{
// ...
};

namespace test
{
// more declarations
}

GlobalClass c;


Share this post


Link to post
Share on other sites
Hi rip-off,

thanks for your reply. Consider the following situation:


namespace test
{
class Object
{
};

REGISTER_CLASS(Object,"Object") // this macro is used to build a class
// registry at compile time
}




Now REGISTER_CLASS is defined as follows:


#define REGISTER_OBJECT(classtype, classname, basetype)BOOST_CLASS_EXPORT_GUID(classtype,classname)\ // compiler traps here
class classtype##Meta
{
public:
classtype##Meta()
{
boost::serialization::void_cast_register(static_cast<classtype *>(NULL),static_cast<basetype *>(NULL));
}
}##classtype##_is_registered;



The compiler traps at the line with BOOST_CLASS_EXPORT_GUID because the macro is used in the namespace test. For simplicity and usability reasons I would like to be able to 'wrap' a global namespace around the macro so that it works. I know that I could use the macro after closing the namespace test, but then I run into other issues which arise from defining the classtype##Meta out of the test namespace (in the real situation the classtype##Meta classes are more elaborate).

Thanks for your time.
David

Share this post


Link to post
Share on other sites
How about this:

namespace test
{
class Object
{
};
}

REGISTER_CLASS(test::Object,"Object") // this macro is used to build a class
// registry at compile time

I haven't really taken the time to understand what you're trying to do, but it seems like this should work.

Edit: No, that won't work I see now. This will try to create a class beginning with test::Object, which is illegal...

Share this post


Link to post
Share on other sites
Quote:
Original post by Perost
How about this:

namespace test
{
class Object
{
};
}

REGISTER_CLASS(test::Object,"Object") // this macro is used to build a class
// registry at compile time

I haven't really taken the time to understand what you're trying to do, but it seems like this should work.

Edit: No, that won't work I see now. This will try to create a class beginning with test::Object, which is illegal...

Use a typedef at global scope then

namespace test
{
class Object
{
};
}
typedef test::Object Serialise_object;
REGISTER_CLASS(Serialise_object,"Object")

Share this post


Link to post
Share on other sites
Quote:

Now REGISTER_CLASS is defined as follows...


That looks like REGISTER_OBJECT to me, and takes a different number of parameters.

Share this post


Link to post
Share on other sites
REGISTER_CLASS == REGISTER_OBJECT, my fault. Thanks for your contributions so far. I'll see what I can do...this whole boost::serialization register stuff drives me crazy...

David

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!