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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:01:36+00:00 2026-05-30T21:01:36+00:00

I have this setup: class DontUse; template<class T,class U = DontUse, class V =

  • 0

I have this setup:

class DontUse;

template<class T,class U = DontUse, class V = SomeStandardType>
class Foo
{
   public:
     void bar(U &uh);
};

When U is set to DontUse, I want bar to be an empty function. In all other cases, I want bar to have some implementation. I tried doing this using specialization, but this code (which I realize is somehow incorrect) doesn’t compile:

template<class T,class V> void Foo<T,DontUse,V>::bar(DontUse &none){}
template<class T,class U,class V> void Foo<T,U,V>::bar(U &uh)
{
  //do something here
}

The error message is this (MSVC10):

1>path_to_project: error C2244: 'Foo<T,U,V>::bar' : unable to match function definition to an existing declaration

and it points to the line of the first template specialization.

How do I do this correctly?

Here’s the actual code, although it’s reduced to the minimalist part that’s relevant:

    struct DontUse;

    template<typename Derived, typename Renderer =  DontUse, typename TimeType = long>
    class Gamestate
    {
    public:

        void Render(Renderer &r);

    };

    template<typename Derived, typename TimeType> void Gamestate<Derived, DontUse,TimeType>::Render( DontUse){}
    template<typename Derived, typename Renderer, typename TimeType> void Gamestate<Derived,Renderer,TimeType>::Render(Renderer &r)
    {
        static_cast<Derived*>(this)->Render(r);
    }
  • 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-30T21:01:37+00:00Added an answer on May 30, 2026 at 9:01 pm

    You cannot specialize individual members of a template. You have to specialize the class itself:

    class DontUse;
    
    template<class T, class V>
    class Foo<T, DontUse, V>
    {
       public:
         void bar(DontUse)
         { }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this model setup public class ListOfThings { public int Id {get;set;}
I have this setup: class A { public: virtual void Function(); } class B
So I have this kind of setup class Base { public: Base(); virtual void
I have a page that is setup like this public partial class _Default :
I have this basic setup: enum{ BASE, PRIMITIVE, ... }; class IUnknown{ public: bool
I Have something similar to this setup: public class Base { public String getApple()
I have a class setup like this public class MyCLass { //... public IList<MyInnerClass>
If I have a simple class setup like this: class MyClass { private string
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I have a two models set up like this: class User < ActiveRecord::Base #

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.