On Sat, Jun 27, 2009 at 3:11 AM, Robert Ryan<[email protected]> wrote:
>
>
>
> #include<iostream>
> using namespace std;
>
> int main()
> {
>
>         const int n = 10;
>         string arrayMax;
>         int num[n] = { 25, 10, 15, 3, 5, 56, 107, 22, 16, 85};
>         cout << "Array:  ";
>         for(int i=0; i<n; i++)
>                 cout << " " << num[i];
>         cout << "\n";
>          // 3.1.2a.cpp:14: no match for call to `(std::string) (int[10],
> const int&)'
>         cout << "The maximum element is:  " << arrayMax(num, n) << "\n";
>         return EXIT_SUCCESS;
> }
>


what are you trying to do here.. you have first created arrayMax using
default constructor and then passing it array adress and integer. It
will surely fail. Probably you want to create string object using
array. Do following:

1. Change array type to char as string constructr never takes int array.
2. Pass this array address to string constrctor not after initialization

int main()
{

        const unsigned int n = 10;
        char num[n] = { 25, 10, 15, 3, 5, 56, 107, 22, 16, 85};
        cout << "Array:  ";
        for(int i=0; i<n; i++)
                cout << " " << num[i];
        cout << "\n";
         // 3.1.2a.cpp:14: no match for call to `(std::string)
(int[10], const int&)'
        string arrayMax(num,n);
        cout << "The maximum element is:  " << arrayMax << "\n";
        return EXIT_SUCCESS;
}

Reply via email to