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

  • Home
  • SEARCH
  • 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 7937507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:32:24+00:00 2026-06-03T22:32:24+00:00

Would someone kindly tell me why the complier flags an error when I attempt

  • 0

Would someone kindly tell me why the complier flags an error when I attempt to call the versions of the member function Foo<T>::setValue that involve more than 1 template argument, as shown below.

See ideone

class Bar
{
public:
    enum TYPE{};
};

//////////////////////////////////////////////////////////////////////////////////////

template<typename T>
class Foo
{
public:
    template<typename P>
    void setValue1();

    template<typename P, int>
    void setValue2();

    template<typename P, typename P::TYPE>
    void setValue3();

private:
    T   m_value;
};

//////////////////////////////////////////////////////////////////////////////////////

template<typename T>
template<typename P>
void Foo<T>::setValue1()
{
}

template<typename T>
template<typename P, int>
void Foo<T>::setValue2()
{
}

template<typename T>
template<typename P, typename P::TYPE>
void Foo<T>::setValue3()
{
}

//////////////////////////////////////////////////////////////////////////////////////

int main()
{
    Foo<Bar::TYPE> f1;

    f1.setValue1<Bar>();                // Compiles
    f1.setValue2<Bar, int>();       // ERROR
    f1.setValue3<Bar, Bar::TYPE>(); // ERROR

    return EXIT_SUCCESS;
}

GCC error:

error: no matching function for call to ‘Foo<Bar::TYPE>::setValue2()’
error: no matching function for call to ‘Foo<Bar::TYPE>::setValue3()’

MSVC .NET 2008 error:

Test6.cpp(60) : error C2975: 'Foo<T>::setValue2' : invalid template argument for 'unnamed-parameter', expected compile-time constant expression
        with
        [
            T=Bar::TYPE
        ]
        Test6.cpp(24) : see declaration of 'Foo<T>::setValue2'
        with
        [
            T=Bar::TYPE
        ]
Test6.cpp(61) : error C2975: 'Foo<T>::setValue3' : invalid template argument for 'unnamed-parameter', expected compile-time constant expression
        with
        [
            T=Bar::TYPE
        ]
        Test6.cpp(27) : see declaration of 'Foo<T>::setValue3'
        with
        [
            T=Bar::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-06-03T22:32:24+00:00Added an answer on June 3, 2026 at 10:32 pm

    I addition to the problem @Jason mentioned, your second function template takes an int as its second argument, and you are providing a type.

    This was fixed by changing the name to setValue2 per @Jason’s post, then changing the function call to:

    f1.setValue2<Bar, 3>();        
    

    I’m not sure what you’re trying to accomplish with the third template function definition. It seems you should only need one template argument, since P::Type can also be derived.

    I should also note that your class definition is not really precise — the class’s template argument is a typename, but you’re passing it Bar::TYPE which is an enum type.

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

Sidebar

Related Questions

Would someone kindly assist me with the following? I have two DataGridView objects that
Would someone kindly explain why the following bit of code works, I've tested it
I am new to Python and would like to know if someone would kindly
Would someone please review this code and tell me why the for loops are
Would someone kindly suggest why the code in the OnKey() method is not executing.
I'm quite confused about several books in .NET that I have read. Would someone
Would someone have a look at this and tell me what I am doing
would someone please write this code: this.Loaded += (s, e) => this.loaded = true;
Would someone be able to break down the Ruby specifics of what each of
Would someone be able to help here? I would like to fill a div

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.