namespace

Hello,

I am quite in c++ programming and I was just trying to use "namesapace". Here is my code:

#ifndef _FUNCTION_CALL_EXTERN_H_
#define _FUNCTION_CALL_EXTERN_H_

namespace first
{
int x = 5;
int y = 10;
}

#endif



It has no relation with any other file; I was just checking how to use the namespace.


The file where is the main function it looks like:


#include "function_call_extern.h"
main()
{
}


When I build my project I get the errors:


error C2061: syntax error : identifier 'first' c:\documents and settings\sferrandiz\mis documentos\visual studio 2010\projects\test.c\test.c\function_call_extern.h line 4 column 1 test.c

error C2059: syntax error : ';' c:\documents and settings\sferrandiz\mis documentos\visual studio 2010\projects\test.c\test.c\function_call_extern.h line 4 column 1 test.c

error C2449: found '{' at file scope (missing function header?) c:\documents and settings\sferrandiz\mis documentos\visual studio 2010\projects\test.c\test.c\function_call_extern.h line 5 column 1 test.c


error C2059: syntax error : '}' c:\documents and settings\sferrandiz\mis documentos\visual studio 2010\projects\test.c\test.c\function_call_extern.h line 8 column 1 test.c



I am using VS 2010. I am getting these errors but I do not know what I am doing wrong.

Thank you very much in advance for your time.

Waso
Does your compiler know that you've written C++ code? Your compiler may be assuming that it is C code because your file is named test.c
Can not "namespace" be used in C code?
Hi Moschops, thank you very much for your quick answer.

When I added the new file I wrote .c, because I was trying to compile the code as a c code. So, although I took the option for a C++ file, I guess the compiler thinks it is a c file.

How could I fix it?

Thank you a lot
Hi Moschops,

I have just created a new C++ project, I put the same code there and I do not get the errors anymore.

So I guess I can not use namespace in C, can I?

Thanks.

Regards, waso
closed account (1vRz3TCk)
No, C does not have namespaces.
Hi CodeMonkey,

thank you very much for your answer.

Regards, waso
Topic archived. No new replies allowed.