Monday

Solutions to C++ error: note: cannot convert '1' (type 'int') to type 'int&'

What is the error of the following program?

#include <iostream>
using namespace std;

template <typename T>
void insert(T& item)
{
    cout << "You cannot have the symbol \"ampersand\" "
<< "as the function parameter passed by value "
<< "to receive the integer number, "
         << "remove the symbol ampersand instead" << endl;
}

int main(int argc, char* argv[])
{
    int integer = 1;

    insert<int>(1);

    return 0;
}

Solutions:
take note that the symbol "ampersand" or "&" cannot be used as
the function parameter passed by value to receive the integer number,
the actual function caller argument, from the main() function body

error: no matching function for call to 'add<int>(int)'
note 1: candidate: 'template<class T> void add(T&)'
note 2: template argument deduction/substitution failed
note 3: cannot convert '1' (type 'int') to type 'int&'

error: note: cannot convert '1' (type 'int') to type 'int&'
Solution:
ampersand or & error at the function parameter
you cannot have the symbol "ampersand" or "&" as the function parameter passed by value,
remove the symbol ampersand or &

No comments:

C++32 (or C++2e), C++ 2032, Cpp 2032, g++ 2032

  Subject: C++ 2032 3 Code example for ? 2 Approximate feature suggestions: - to complete C++29 or C++ 2029 1 Web links, references Wandbox,...