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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:43:05+00:00 2026-06-04T23:43:05+00:00

This is an interview question, which has been done. Which line has error ?

  • 0

This is an interview question, which has been done.

Which line has error ?

  #include<iostream>
  template<class T> void foo(T op1, T op2)
  {
      std::cout << "op1=" << op1 << std::endl;
      std::cout << "op2=" << op2 << std::endl;
  }

  template<class T>
  struct sum
  {
      static void foo(T op1, T op2)
      {
              std::cout << "sum=" << op2 << std::endl ;
      }
  };

  int main()
  {
      foo(1,3);  // line1
      foo(1,3.2);  // line2
      foo<int>(1,3);  // line3
      foo<int>(1, '3') ; // line 4
      sum::foo(1,2) ; // line 5  , 

      return 0;
  }

Line 2 has error because the template parameter is not matching the definition.
Line 5 has error because the template parameter is missing.

But, Line 1 is an not an error, I do not know why, does not it also miss template parameter ?

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-06-04T23:43:08+00:00Added an answer on June 4, 2026 at 11:43 pm

    It’s called type deducition.

    On Line 1, the type of T can be deduced because parameters op1 and op2 are both int, making T an int.

    Whereas on Line 2, you are passing both an int and a double while the function accepts both parameters as T, the compiler has no clue whether T should be a double or an int.

    Line 3 is fine because you specify int specialization and pass ints in as well (making the specialization redundant but perfectly OK).

    Line 4 is OK because you declare T to be an int, then casting the char value of '3' to its numeric int value.

    Line 5 is an error because you’re accessing a function that gets its type from the templated struct it’s in, and type deduction only works for functions.

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

Sidebar

Related Questions

This is an interview test question not homework. The test has been done. Which
This was the question asked to me in an interview in c: #include<stdio.h> void
This is an interview question. I have K machines each of which is connected
Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis)
I was asked in an interview this question LinkedList A has {1,2,3,4,5,6} LinkedList B
This is a interview Question which was asked and wanted to find an efficient
I came across this post , which reports the following interview question: Given two
This is the interview question asked. Which is the most important factor while drawing
So, this is a common interview question. There's already a topic up, which I
Got asked this interesting interview question today. Explain in detail the process by which

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.