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 6999599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:33:45+00:00 2026-05-27T20:33:45+00:00

I have a bunch of templated code that compiles fine under g++, but now

  • 0

I have a bunch of templated code that compiles fine under g++, but now when I try to build under windows with Visual C++ 2010 I get a bunch of errors.

I have a collection of template functions for getting and setting values in C++ objects from Lua code. For example, I have this template:

//        Class       Return type Getter function
template <typename T, typename U, U (T::*Getter)() const>
int luaU_get(lua_State* L)
{
    T* obj = luaW_check<T>(L, 1); // Gets userdata from stack and checks if it's of type T
    luaU_push(L, (obj->*Getter)()); // Runs the getter function specified in the template, and pushes the
    return 1;
}

(The complete file can be found here)

Which is instantiated here:

static luaL_reg TextArea_MT[] =
{
    //                             Class     Return type   Getter function
    { "GetCharacterSize", luaU_get<TextArea, unsigned int, &TextArea::GetCharacterSize> },
    { NULL, NULL }
};

The signature for that getter is as follows:

unsigned int GetCharacterSize() const;

I’m getting a bunch of errors like this:

2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int *(__thiscall ag::ui::TextArea::* const )(void) const'
2>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
2>          C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\extern\LuaWrapper\LuaWrapperUtil.hpp(147) : see declaration of 'luaU_get'
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int *ag::ui::TextArea::* const '
2>          There is no context in which this conversion is possible
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
2>          C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\extern\LuaWrapper\LuaWrapperUtil.hpp(131) : see declaration of 'luaU_get'
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2440: 'specialization' : cannot convert from 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const' to 'unsigned int ag::ui::TextArea::* const '
2>          There is no context in which this conversion is possible
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2973: 'luaU_get' : invalid template argument 'unsigned int (__thiscall ag::ui::TextArea::* )(void) const'
2>          C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\extern\LuaWrapper\LuaWrapperUtil.hpp(123) : see declaration of 'luaU_get'
2>C:\Users\Alex\Documents\Visual Studio 2010\Projects\game\dev\src\game\lua\LuaTextArea.cpp(103): error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'lua_CFunction'
2>          None of the functions with this name in scope match the target type
  • 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-27T20:33:45+00:00Added an answer on May 27, 2026 at 8:33 pm

    This is a compiler bug in VC++. The following code is valid:

    #include <iostream>
    
    struct TextArea
    {
        unsigned GetCharacterSize() const { return 0; }
    };
    
    template<typename T, typename U, U (T::*)() const>
    int foo()
    {
        return 1;
    }
    
    template<typename T, typename U, U* (T::*)() const>
    int foo()
    {
        return 2;
    }
    
    int main()
    {
        std::cout << foo<TextArea, unsigned, &TextArea::GetCharacterSize>() << '\n';
    }
    

    And compiles with GCC 4.3.4, GCC 4.5.1, and Comeau 4.3.10.1 Beta2 (no link), but yields the following error with VC++ 2010 SP1:

    error C2668: 'foo' : ambiguous call to overloaded function


    EDIT: As for a workaround, it’s ugly, but the only thing I can think of offhand is to use an extra layer of indirection so that there is no overloading involved:

    #include <iostream>
    
    struct WithPointer
    {
        unsigned* GetCharacterSize() const { return nullptr; }
    };
    
    struct WithoutPointer
    {
        unsigned GetCharacterSize() const { return 0u; }
    };
    
    template<bool UsePointerImplB>
    struct kludge
    {
        template<typename T, typename U, U (T::*Getter)() const>
        static int foo() { return 1; }
    };
    
    template<>
    struct kludge<true>
    {
        template<typename T, typename U, U* (T::*Getter)() const>
        static int foo() { return 2; }
    };
    
    int main()
    {
        std::cout
            << kludge<false>::foo<WithoutPointer, unsigned, &WithoutPointer::GetCharacterSize>() << '\n'
            << kludge<true>::foo<WithPointer, unsigned, &WithPointer::GetCharacterSize>() << '\n';
    }
    

    Effectively this is no different than just giving each overload a different name…

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

Sidebar

Related Questions

I have a bunch of related indicies in a kind of templated hierarchy, looking
I have a bunch of templates that are used for rpc and was wondering
I have a bunch of Velocity template files in a Visual Studio 2008 project,
I have a bunch of files that I need to be able to transport
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on
I have a bunch of .NET frameworks installed on my machine. I know that
I've come into ownership of a bunch of MATLAB code and have noticed a
I have android application that is written regular way. layouts, java, APK. Now, depending
Say I have a bunch of code for all controls, yet I need subclasses
I have a model with a bunch of choices, that are in the DB

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.