473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

anonymous namespace issue

I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous namespace'::f(void)"

What have I done wrong? Thanks.
Oct 21 '05 #1
8 5847
Geo

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous namespace'::f(void)"

What have I done wrong? Thanks.


Exactly what it say, you've not supplied a definition for

bool __cdecl `anonymous namespace'::f(void)

Oct 21 '05 #2

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous namespace'::f(void)"

What have I done wrong? Thanks.


The definition for f() must be inside the anonymous namespace. After
all, the namespace has no name, so there's no way to qualify f() to
place it in the anonymous namespace.

Greg

Oct 21 '05 #3
"Geo" <gg@remm.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous
namespace'::f(void)"

What have I done wrong? Thanks.


Exactly what it say, you've not supplied a definition for

bool __cdecl `anonymous namespace'::f(void)


How do I supply one? Do I need to write this?

namespace
{
void f() { std::cout << "hello world" << std::endl; }
}

If I don't want to define f in the block of the anonymous namespace, where
can I define it and how? I tried this but it won't compile.

namespace { void f(); }
void ::f() { std::cout << "hello world" << std::endl; }

NB: I use VC++ 6.0.
Oct 21 '05 #4
"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous
namespace'::f(void)"

What have I done wrong? Thanks.


The definition for f() must be inside the anonymous namespace. After
all, the namespace has no name, so there's no way to qualify f() to
place it in the anonymous namespace.


Thank you for your answer.

I'm curious. Why does this code compile successfully if what you say is
true?

namespace n
{
namespace
{
void f();
}
}

void n::f() { }

int main()
{
n::f();
return 0;
}
Oct 21 '05 #5
Jason Heyes wrote:
If I don't want to define f in the block of the anonymous namespace, where
can I define it and how?


Why do you want to define it outside the anonymous namespace if you declared
it inside?

Oct 21 '05 #6
Jason Heyes wrote:
"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous
namespace'::f(void)"

What have I done wrong? Thanks.


The definition for f() must be inside the anonymous namespace. After
all, the namespace has no name, so there's no way to qualify f() to
place it in the anonymous namespace.


Thank you for your answer.

I'm curious. Why does this code compile successfully if what you say is
true?

namespace n
{
namespace
{
void f();
}
}

void n::f() { }

int main()
{
n::f();
return 0;
}


It should not. n::f() does not exists. This example is functionally
equivalent to:

namespace n
{
namespace m
{
void f();
}

using namespace m;
}

void n::f()
{
}

which is clearly illegal. Your compiler is broken.
Jonathan

Oct 21 '05 #7

Jason Heyes wrote:
"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous
namespace'::f(void)"

What have I done wrong? Thanks.


The definition for f() must be inside the anonymous namespace. After
all, the namespace has no name, so there's no way to qualify f() to
place it in the anonymous namespace.


Thank you for your answer.

I'm curious. Why does this code compile successfully if what you say is
true?

namespace n
{
namespace
{
void f();
}
}

void n::f() { }

int main()
{
n::f();
return 0;
}


This program should generate this error:

test.cc:9: error: 'void n::f()' should have been declared inside 'n'

Even without the error, n::f() refers to an f() inside namespace n and
not within an inner, anonymous namespace.

Greg

Oct 21 '05 #8
"Geo"

Jason Heyes wrote:
I wrote:

namespace { void f(); }
void f() { std::cout << "hello world" << std::endl; }

When I compile, I receive this error:

unresolved external symbol "bool __cdecl `anonymous namespace'::f(void)"
What have I done wrong? Thanks.


Exactly what it say, you've not supplied a definition for

bool __cdecl `anonymous namespace'::f(void)


Presumably f() is called, and the global f() is in a different
translation unit or there would be ambiguity with the function call
resolution.

Fraser.
Oct 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Cordell Lawrence | last post by:
Okay guys, We are wondering if this is a bug in Framework 2.0.40607 and looking for some clarification on the issue. Take a look at the folowing code. public delegate bool BoundryTest(int...
3
by: anonymous | last post by:
I believe I ran into an interesting way to create memory leaks in C# 2.0 using anymous delegates. Here is a sample of the code in question. private void Handle_Event(object sender, EventArgs e)...
3
by: Frederick Gotham | last post by:
Back in the day, if you wanted a function to be self-contained within a translation unit, you defined the function as "static". If there were an external linkage function by the same name...
6
by: 2b|!2b==? | last post by:
I have the following declaration in a header file (MyClass.h) //contents of MyClass.h class MyClass { public: MyClass() MyClass(const MyClass&); ... };
1
by: ktrvnbq02 | last post by:
Hi, I recently came to debug some old code that was causing a StackOverflowException. The code in question makes significant use of recursion and with large data structures it exhausted the...
12
by: Taras_96 | last post by:
Hi everyone, AFAIK external linkage allows you to refer to variables/functions outside of the current translation unit. A variable in an unnamed namespace is similar to declaring a static...
5
by: gauravbjain | last post by:
I am planning to move from ‘static’ keyword to anonymous namespace for variables/functions which are local to a translation unit. This is to move code closer to C++, since static for file level...
22
by: Luna Moon | last post by:
I am reading the book "C++ Annotations", and here is a quote from the book: Namespaces can be defined without a name. Such a namespace is anonymous and it restricts the visibility of the...
8
by: Tim Chase | last post by:
I've got code similar to the following class Action: def __init__(self, ...): pass def __call__(self, ...): pass def get_help(self, ...): pass class Backend: class _Load(Action): def...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.