| re: Unnamed namespace predicament...
Tomás wrote:[color=blue]
> I have a header file/source file combo.
>
> There's approximately five functions in the source file. Only one of the
> functions should be used by other translation units, so I've defined the
> other four functions within an unnamed namespace. The header file only
> contains a declaration for the one function.
>
> My function needs to call the other four functions. My code won't compile,
> giving the following error:
>
> c:\>g++ code.cpp -ansi -pedantic -o program.exe
> C:\Temp/ccUvbaaa.o(.text+0x7):code.cpp: undefined reference to `Ape()'
>
> Here's the sample code file which demonstrates the problem:
>[/color]
Put this new declaration here -
namespace { void Ape(); }[color=blue]
> void Monkey()
> {[/color]
Comment out the follg declaration[color=blue]
> void Ape(); //Function Declaration
>
> Ape();
> }
>
> namespace {
>
> void Ape()
> {
> ;
> }
>
> }
>
>
> int main()
> {
> Monkey();
> }
>
>
>
> If I switch the order around, as follows:
>
>
>
> namespace {
>
> void Ape()
> {
> ;
> }
> }
>
> void Monkey()
> {
> Ape();
> }
>
> int main()
> {
> Monkey();
> }
>
>
> Then my code compiles without error.
>
> In order for me to be able to put "Monkey" first, then I need to declare
> "Ape" before I use it. So how do I declare "Ape"? I've tried declaring it
> both inside the function "Monkey" and outside the function "Monkey", but
> neither will work. Also I've tried:
>
> void ::Ape();
>
> but that doesn't work either. I've also tried putting "extern" before it,
> but to no avail.
>
>
> -Tomás[/color] |