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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:47:39+00:00 2026-06-12T07:47:39+00:00

Given the following code: template<typename T> class A { public: T t; }; class

  • 0

Given the following code:

template<typename T>
class A
{
public:
   T t;
};

class B
{
public:
   void foo(int i) {}

   template<typename T>
   void foo(A<T>& a) {}
};

int main()
{
   A<int> a;
   B      b;

   b.foo(a  );
   b.foo(a.t);
}

This compiles and works fine; the correct overloaded versions of B::foo() are chosen and called for a and a.t.

Now I introduce a new class C which derives from B and move the template version of ::foo() out of B and into C:

template<typename T>
class A
{
public:
   T t;
};

class B
{
public:
   void foo(int i) {}
};

class C: public B
{
public:
   template<typename T>
   void foo(A<T>& a) {}
};

int main()
{
   A<int> a;
   C      c;

   c.foo(a  ); // Fine
   c.foo(a.t); // Error
}

And now the code won’t compile anymore. Visual Studio 2005 is stating:

error C2784: 'void C::foo(A<T> &)' : could not deduce template argument for 'A<T> &' from 'int'

In fact, calling C::foo() with any int value results in this error. It almost seems like the method overload for int is being hidden by the template overload.

Why is this happening? Is it some issue with Visual Studio 2005’s compiler? Unfortunately, I cannot test it on any other compiler right now.

Any information is appreciated.

  • 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-12T07:47:40+00:00Added an answer on June 12, 2026 at 7:47 am

    It almost seems like the method overload for int is being hidden by the template overload.

    Exactly! You need to add a using declaration to class C:

    class C: public B
    {
     public:
      using B::foo;
      template<typename T>
      void foo(A<T>& a) {}
    };
    

    When you declare a member function in a derived class, all member functions in the base class with the same name are hidden. See §3.3.10/3 of ISO/IEC 14882:2011:

    The declaration of a member in a derived class (Clause 10) hides the declaration of a member of a base class of the same name; see 10.2.

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

Sidebar

Related Questions

Given this code: class X { public: template< typename T > void func( const
So given the following template functions with partial specialization template<typename T> void foo(vector<T> &in)
Given the following code: void f() { class A { template <typename T> void
The following code compiles fine: template<typename T> void f(const T &item) { return; }
Given the following piece of code: template<typename T> class MyContainer { typedef T value_type;
Consider this code: template<typename T> class Base { template<typename U> friend void f(void *ptr)
Look at following code: template <typename T, int d> class Grid { //Following line
Consider this template: template< typename T, typename RefT = T& > class foo {
Given the following code: final class retVal { int photo_id; } Gson gson =
please consider the following code: template <typename T> struct foo { template <typename S>

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.