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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:38:23+00:00 2026-06-11T19:38:23+00:00

What is wrong with the following piece of code? #include <iostream> template<typename K> struct

  • 0

What is wrong with the following piece of code?

#include <iostream>

template<typename K>
struct A {
    struct X { K p; };
    struct Y { K q; };
};

template<typename K>
void foo(const typename A<K>::X& x, const typename A<K>::Y& y) {
    std::cout << "A" << std::endl;
}

int main() {
    A<float>::X x;
    A<float>::Y y;
    foo(x, y);  
}

clang gives the following error message:

17:2: error: no matching function for call to 'foo'
        foo(x, y);      
        ^~~
10:6: note: candidate template ignored: couldn't infer template argument 'K'
void foo(const typename A<K>::X& x, const typename A<K>::Y& y) {
     ^
1 error generated.
  • 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-11T19:38:24+00:00Added an answer on June 11, 2026 at 7:38 pm

    The argument K in const typename A<K>::X is not deducible. Basically, everything left of a :: is not deducible (if :: separates a nested-name).

    It’s trivial to see why it makes no sense to ask for deduction by running through this thought experiment:

    struct A { typedef int type; }
    struct B { typedef int type; }
    
    template <typename T> void foo(typename T::type);
    
    foo(5);   // is T == A or T == B ??
    

    There’s no one-to-one mapping from types to nested types: Given any type (such as int), there could be many ambient types of which it is a nested type, or there needn’t be any.

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

Sidebar

Related Questions

Consider this piece of code: #include <iostream> #include <vector> template<typename A> void foo(A& a)
What is wrong with the following piece of code? template<typename X> struct A {
I have the following piece of TCL code: #wrong format: set in_val 12 0
Let's look at the following piece of code which I unintentionally wrote: void test
Whats wrong with the following piece of code: UIButton *button = [[UIButton alloc]init]; CGRect
What's wrong with the following piece of code that the program crashes - give
I have for example the following piece of code: string str; int i; cout<<input:;
I have the following seemingly innocuous piece of code: #ifndef UI_H #define UI_H #include
I have following piece of code: typedef uint8_t array_t[8]; static array_t _my_array; static const
The following piece of code works perfectly in script/console but returns the following error

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.