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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:14:23+00:00 2026-05-16T04:14:23+00:00

I have following code: #include <iostream> using namespace std; template<class T> T max(T *data,int

  • 0

I have following code:

#include <iostream>
using namespace std;
template<class T>
T max(T *data,int len){
    int i;
    T Max=data[0];

     for (int i=1;i<len;i++){

         if (data[i]>max){
             Max=data[i];


     }
     }
 return  Max;

}
int mai(){
    int i[]={12,34,10,9,56,78,30};
    int len=sizeof(i)/sizeof(i[0]);
    cout<<max(i,len)<<"\n";



     return 0;
}

But when I compile it, I get the following errors:

generic_max, Configuration: Debug Win32 ------
1>Build started 7/29/2010 1:03:25 AM.
1>InitializeBuildStatus:
1>  Touching "Debug\generic_max.unsuccessfulbuild".
1>ClCompile:
1>  generic_max.cpp
1>c:\users\david\documents\visual studio 2010\projects\generic_max\generic_max\generic_max.cpp(10): error C2563: mismatch in formal parameter list
1>          c:\users\david\documents\visual studio 2010\projects\generic_max\generic_max\generic_max.cpp(22) : see reference to function template instantiation 'T max<int>(T *,int)' being compiled
1>          with
1>          [
1>              T=int
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\generic_max\generic_max\generic_max.cpp(10): error C2568: '>' : unable to resolve function overload
1>          c:\users\david\documents\visual studio 2010\projects\generic_max\generic_max\generic_max.cpp(4): could be 'T max(T *,int)'
1>          c:\program files\microsoft visual studio 10.0\vc\include\xutility(2086): or       'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)'
1>          c:\program files\microsoft visual studio 10.0\vc\include\xutility(2078): or       'const _Ty &std::max(const _Ty &,const _Ty &)'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.95
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please help me to fix this problem.

  • 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-16T04:14:24+00:00Added an answer on May 16, 2026 at 4:14 am

    C++ is case-sensitive.

    #include <iostream>
    
    // Note the omission of `using namespace std;`. The declaration can
    // introduce clashes if one of your functions happen to have the same name
    // as the functions in the std namespace.
    
    template<class T> 
    T max(T *data,int len) { 
        //int i; <-- Not needed? The for loop already has an `i` declared in it.
        T Max=data[0]; 
    
        for (int i=1;i<len;i++) { 
            /****** Note `Max`, not `max` ******/
            // The typo in your code snippet is what's causing the C2563.
            // `max` (in this context) refers to the function
            // `template<class T> T max(T *data,int len)` that has been declared.
            // `Max` refers to the variable declared in this function. 
            // (For the sake of readability, variable names should not similar
            // to the function name). 
            if (data[i]>Max) {
                Max=data[i]; 
            } 
        } 
        return  Max; 
    } 
    
    /****** Note `main()`, not `mai()` ******/
    int main() {
        int i[]={12,34,10,9,56,78,30}; 
        int len=sizeof(i)/sizeof(i[0]);
        // `cout` should be just qualified with `std::` instead of
        // `using namespace std`. 
        std::cout<<max(i,len)<<"\n";
        return 0; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following code #include <iostream> #include <utility> using namespace std; namespace rel_ops{ template<class
I have written the following code: #include <iostream> using namespace std; template <class T>
I have the following code: #include <iostream> using namespace std; class testing{ int test()
i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class
I have the following code: #include <iostream> using namespace std; template <class T> class
i have following fragment of code #include<iostream> #include<cstring> using namespace std; class data {
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc
I have the following code compiled by gcc: #include <iostream> using namespace std; class
i have following code #include <iostream> using namespace std; int main(int argc,char arg[]){ int
I have the following C++ code: #include <iostream> #include <vector> using namespace std; class

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.