3

I'm recently visiting namespaces as I have a group of functions/methods but no data, so the logical way to go would be to stick them inside a namespace. (Sorry if this question lacks anything).

I have the following:

Math.h

namespace Math {

   double Euclidean();

}

Math.cpp

#include "Math.h"
double Math::Euclidean() {
  // Implementation
}

And in another namespace, that I need to access the "Math" namespace:

namespace foo {

     foo();
}

Foo.cpp

#include "Math.h"
#include "foo.h"

using namespace Math; 

foo::foo() {
  // use the math function
  Math::Euclidean();  

}

I get the error:

Math’ is not a namespace-name

I'm probably missing something really simple, but, I cannot seem to figure it out.

I have tried to read the following: Here but it seems that this uses a class and I wanted to do it without using classes.

8
  • 2
    Which line are you getting the error on? The double Math::Euclidiean(), the using namespace Math; or somewhere else? Commented Mar 18, 2013 at 17:10
  • 8
    "math.h" is also a C standard header. Perhaps that's what the compiler is including. Commented Mar 18, 2013 at 17:11
  • Did you forget to paste some includes from the headers? Commented Mar 18, 2013 at 17:15
  • @BoPersson Even if I change the namespace to say some and change everything to this, I still get the error: ‘some’ is not a namespace-name Commented Mar 18, 2013 at 17:24
  • 2
    @Phorce - What about changing the name of the include file? "Phorce_Math.h", for example, isn't already taken. Commented Mar 18, 2013 at 17:28

1 Answer 1

4

This question has gotten stale for an hour, so I'm promoting @Bo Persson's intuitive comment.

"math.h" is also a C standard header. Perhaps that's what the compiler is including.

You are likely using Windows, where Math.h and math.h describe the same file.

Rename your file so it doesn't have the same name as a standard library header and the compiler will see it.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not using windows, no. But, I've just got home so I will do what you suggested, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.