Jump to content
  • Advertisement
Sign in to follow this  
VprMatrix89

namespace trouble

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

error C2653: 'bcmath' : is not a class or namespace name I have a class that uses a struct of a namespace, and when I say something like bcmath::BOX abox; it says there is no such namespace. However, when defining, it actually works. For example, one of my functions takes this as a parameter, but it only gives an error on the declaration within the class declaration, which is in the .h file of the class. the namespace is in a seperate .h file, which main.h includes. How can I get this to work?

Share this post


Link to post
Share on other sites
Advertisement
#ifndef bc_Math_h
#define bc_Math_h

#include "main.h"

namespace bcmath {

struct bcPOINT{
float x,y,z;
}
}

#endif






#include "main.h"

#ifndef ClipMap_h
#define ClipMap_h


class ClipMap
{

public:
bcmatch::bcPOINT a;
}

#endif



And both of these are included in main.h to link them together. The math file is included before the clipmap file... For some reason, the way everything is built, it forced me to do the #ifndef part, and I dont know why.

[Edited by - VprMatrix89 on July 21, 2008 10:29:40 AM]

Share this post


Link to post
Share on other sites
If both of these are included in main.h, they should not include main.h themselves. You should only include "main.h" in files that need something in main.h to work. From what you posted, neither of these files need main.h.

Also your namespace declaration seems to be missing a closing brace.

Share this post


Link to post
Share on other sites
why do you call the struct 'bcPOINT' when it's in a namespace called 'bcmath', why not just 'POINT' ?

Share this post


Link to post
Share on other sites
I fixed the typos... But as far as not needing main, this may be true, however even if I directly include the other .h which holds the namespace, there is no difference.

It might have something to do with ifndef.. cause right now I dont understand that part and it effects compilation.

Share this post


Link to post
Share on other sites
Here's a bcmath.h
#ifndef bc_Math_h
#define bc_Math_h

namespace bcmath {

struct POINT
{
float x,y,z;
};
}

#endif


and here's a clipmap.h
#ifndef ClipMap_h
#define ClipMap_h

#include <bcmath.h>

class ClipMap
{
public:
bcmatch::POINT a;
};

#endif


And finally, here's a main.h
#ifndef main_h
#define main_h

#include <clipmap.h>

#endif


This should now work: header files are idempotent and include all required declarations. Try it and see if it works.

Share this post


Link to post
Share on other sites
Jeez what a mess, somehow the interdependencies confused the compiler I guess.
I just got home and compiled, and it worked, by cutting down on the includes. Thanks for the help

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!