1. namespace question
- Posted by bugmagnet Aug 05, 2012
- 1197 views
Can one have more than one namespace per file? That is, in some_demo.e can one have:
namespace a integer n = 1 namespace b integer n = 1 namespace c integer n = 1
It would appear not, at this stage anyway, because evaluating the above gives
>eui some_demo.e C:\euphoria\dev\euJSON\some_demo.e:5 <0031>:: attempt to redefine n. integer n = 1 ^
Kind regards,
Bruce/bugmagnet
2. Re: namespace question
- Posted by mattlewis (admin) Aug 05, 2012
- 1113 views
Can one have more than one namespace per file? That is, in some_demo.e can one have:
[snip]
It would appear not, at this stage anyway, because evaluating the above gives
No, namespaces are basically file-based. In order to declare a default namespace for a file, the namespace directive must be the first non-comment in the file. When the parser sees subsequent instances of the token "namespace" it interprets them as a user defined type.
Matt
3. Re: namespace question
- Posted by ghaberek (admin) Aug 05, 2012
- 1054 views
Can one have more than one namespace per file? That is, in some_demo.e can one have:
namespace a integer n = 1 namespace b integer n = 1 namespace c integer n = 1
No, but you could do the following...
file_a.e
namespace a public integer n = 1
file_b.e
namespace b public integer n = 2
file_c.e
namespace c public integer n = 3
abc.e
public include file_a.e public include file_b.e public include file_b.e
test.ex
include abc.e printf( 1, "a:n = %d\n", a:n ) printf( 1, "b:n = %d\n", b:n ) printf( 1, "c:n = %d\n", c:n )
This method may seem a bit more complicated, but when you're writing large applications, it's actually much better to separate your code into logically separate files. Also, remember to mind your scopes and declare things as public when you want them to be visible outside of their own file (and therefore their namespace).
-Greg