Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 570605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:25:10+00:00 2026-05-13T13:25:10+00:00

Apparently, MSVC2005 fails to inline local classes’ member functions which leads to LNK2005. I’m

  • 0

Apparently, MSVC2005 fails to inline local classes’ member functions which leads to LNK2005.

I’m facing this LNK2005 error when compiling the following:

common.h content:

inline void wait_what()
{
  struct wtf
  {
    void ffffuuu() {}

  } local;
}

foo.cpp content:

#include "common.h"

void foo()
{
  wait_what();
}

bar.cpp content:

#include "common.h"

void bar()
{
  wait_what();
}

LNK2005.cpp content:

// forward declarations
void foo();
void bar();

int main()
{
  foo();
  bar();

  return 0;
}

The error message is:

error LNK2005: "public void __thiscall `void__cdecl wait_what(void)'::`2'::wtf::ffffuuu(void)" (?ffffuuu@wtf?1??wait_what@@YAXXZ@QAEXXZ) already defined in bar.obj

About local classes, ISO IEC 14882-2003 says:

9.8 Local class declarations

A class can be defined within a function definition; such a class is called a local class. The name of a local class is local to its enclosing scope. The local class is in the scope of the enclosing scope, and has the same access to names outside the function as does the enclosing function. Declarations in a local class can use only type names, static variables, extern variables and functions, and enumerators from the enclosing scope.

An enclosing function has no special access to members of the local class; it obeys the usual access rules (clause 11). Member functions of a local class shall be defined within their class definition, if they are defined at all.

Did I miss something?

To me, it looks like it is a compiler bug. GCC and MSVC2008 compile it just fine. However, I wonder whether they would really inline the call or just discard one of the two symbols during the link phase. As an interesting note, you can notice that there is even no call to this local class member function.

I wonder whether there is a workaround for MSVC2005. I tried to search MSDN for this typical problem without much success: I wasn’t even capable of finding a list of known bugs for the compiler.


Attachment: LNK2005.zip

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:25:10+00:00Added an answer on May 13, 2026 at 1:25 pm

    it was a bug in visual studio 2005, it was fixed in vs 2008

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently, this code gives me error at the last line cvCvtColor(), what is wrong?
Apparently using the URL is no good - why is this the case, and
Apparently many people have run into this problem, but I have yet to be
Apparently I've done something I'm not aware of All my classes now have warnings
Apparently this Tomcat data source gets registered in JNDI. The crystal reports API will
Apparently this line of code is triggering Object expected: var bPid = (b !=
Apparently this used to be a way in VB6 and VBA to short circuit
Apparently this function in SDL_Mixer keeps dying, and I'm not sure why. Does anyone
Apparently (because the documentation doesn't say any word of this), in a .NET Transaction
Apparently this problem comes up fairly often, after reading Regular expression to detect semi-colon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.