Sunday

Solutions to C++ error: expected unqualified-id before 'delete' and C++ error: expected primary-expression before ')' token

What are the two errors of the following program?

#include <iostream>
using namespace std;

void delete()
{
    cout << "You cannot have the word \"delete\" "
         << "as the function name or variable name, "
         << "choose other name instead" << endl;
}

int main(int argc, char* argv[])
{
    delete();

    return 0;
}

Solutions:
take note that the keyword "delete" cannot be used as the function name or variable name

Error 1: expected unqualified-id before 'delete'
Solution:
function name error at the function header
you cannot have the word "delete" as the function name, variable name
use different function name such as deleteNode

Error 2: expected primary-expression before ')' token
Solution:
function caller name error in the main function body
you cannot have the word "delete" as the function caller name, function name, variable name
use different function name such as deleteNode

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,...