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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:05:58+00:00 2026-05-23T11:05:58+00:00

struct Test { template <class T> void print(T& t) { t.print(); } }; struct

  • 0
struct Test
{
        template <class T>
        void print(T& t)
    {
        t.print();
    }
};

struct A
{
    void print() {printf( "A");}
};

struct B
{
    void print() {printf( "B");}
};

void test_it()
{   
    A a;
    B b;

    Test t;
    t.print(a);
    t.print(b);
}

This compiles fine.

struct Test
{
        template <class T>
        void print(T& t)
    {
        t.print();
    }
};


void test_it()
{   
    struct A
    {
        void print() {printf( "A");}
    };

    struct B
    {
        void print() {printf( "B");}
    };

    A a;
    B b;

    Test t;
    t.print(a);
    t.print(b);
}

This fails with error :
no matching function for call to ‘Test::print(test_it()::A&)’

Can anyone explain me why this happen ?
Thanks!!!

  • 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-23T11:05:59+00:00Added an answer on May 23, 2026 at 11:05 am

    In your second example, A and B are local types, which can’t be used as template type arguments in C++03 as per §14.3.1/2:

    A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.

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

Sidebar

Related Questions

Code: template<class T> struct A { void f1() {}; void f2() {}; }; template<>
Following code fails with a error message : t.cpp: In function `void test()': t.cpp:35:
Please consider the following code. struct foo { }; template<typename T> class test {
is it possible to do something like the following: struct test { this {
For example, I have a struct which is something like this: struct Test {
I have a simple container : template <class nodeType> list { public: struct node
I am using CPPUnit to test a class in my program. This class (
I have this sample code: struct A { bool test() const { return false;
I have a class A: template <typename T, int I> struct A {}; and
I have a class template <typename T> struct Trait { typedef std::false_type IsGood; };

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.