error C2064

This is a discussion on error C2064 within the C++ Programming forums, part of the General Programming Boards category; I am testing out a simple template, but every time i try it, this error C2064 : term does not ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    12

    error C2064

    I am testing out a simple template, but every time i try it, this error C2064 : term does not evaluate to a function taking 0 arguments, pops up. Seen as i am very new to C++, it will probabily be something stupid, but if i don't ask i'll never find out.
    Code:
    #include <iostream>;
    #include <cstdlib>;
    
    using namespace std;
    
    int main()
    {
     int input;
       
      cout<<"1. Play game\n";
      cout<<"2. Load game\n";
      cout<<"3. Play multiplayer\n";
      cout<<"4. Exit\n";
      cout<<"Selection: ";
      cin>> input;
      switch ( input ) {
      case 1:            
        playgame();
        break;
      case 2:           
       loadgame();
        break;
      case 3:           
        playmultiplayer();
        break;
      case 4:           
        cout<<"Thank you for playing!\n";
        break;
      default:          
        cout<<"Error, bad input, quitting\n";
        break;
      }
      cin.get();
    }
    Thanks for help in advance.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Which line?
    Is it one of the

    playgame();
    loadgame();
    playmultiplayer();

    ?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    12
    Sorry should have mentioned that. Unfortunately it's all three.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Then it's because you haven't defined those functions. You cannot call a function that does not exist, can you?
    Also,

    #include <iostream>;
    #include <cstdlib>;

    should be

    #include <iostream>
    #include <cstdlib>
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    12
    Then it's because you haven't defined those functions
    Sorry like i said i'm new, how do you mean?

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Those functions have to be declared before you use them.

    Code:
    void playgame();
    //etc
    And then they need to be implemented somewhere

    Code:
    void playgame()
    {
        //implementation
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    Quote Originally Posted by ftball22 View Post
    Sorry like i said i'm new, how do you mean?
    Essentially, you haven't created the functions. They don't exist.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    I saw from your previous thread that you were struggling with functions.

    Here, the function menu() uses the return statement to return choice: Notice the function is declared above main() and implemented below.


    Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int menu();
    
    int main(){
        int choice = menu();
        cout << "You chose option " << choice << endl;
        
        system ("pause"); // temp to stop console closing
        return 0;
    }
    
    int menu(){
        int choice;
    
        cout << " **** Menu ****" << endl << endl;
        cout << "(1) Option 1." << endl;
        cout << "(2) Option 2." << endl;
        cout << "(3) Option 3." << endl;
        cout << "(4) Redisplay menu." << endl;
        cout << "(5) Quit." << endl << endl;
    
        cout << ": ";
        cin >> choice;
        return choice;
    }

    In your select statement, there is no value to be returned, so in this case you would use a void type for the function and declare and implement it as anon has pointed out above.

    To be honest, as a beginner myself, Iím not sure why this is referred to as a function.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    The way I understand it is.....

    The compiler 'reads' from the top of the code down.

    It has to have already 'read' what a function does before you can use the function (well, at least the function name, input and output).

    If you declare a function twice, the first one is over-written by the second one. So you can just declare an empty 'prototype' for the function and fill the details in later in the code.

    You could also just write the functions in a different order (but this gets impossible to do in big programs).

    Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    //we need to use menu() in main() so it must appear before main() 
    int menu()
    {
        int choice;
    
        cout << " **** Menu ****" << endl << endl;
        cout << "(1) Option 1." << endl;
        cout << "(2) Option 2." << endl;
        cout << "(3) Option 3." << endl;
        cout << "(4) Redisplay menu." << endl;
        cout << "(5) Quit." << endl << endl;
    
        cout << ": ";
        cin >> choice;
        return choice;
    }
    
    int main()
    {
        int choice = menu();
        cout << "You chose option " << choice << endl;
        
        system ("pause"); // temp to stop console closing
        return 0;
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,606
    The compiler will parse a file top to bottom. To use something, or call a function, we must first make the compiler aware of that identifier, such as a type or a function.
    This is done by declaring an identifier. This basically introduces the identifier to the compiler. The compiler now knows this identifier exists, but it has as of yet no idea what it is, or what it contains. Under certain circumstances, this is fine. For functions, for example, it is fine.
    Then comes the "definition" part, which formally introduces this identifier to the compiler. The definition will tell the compiler exactly what this identifier is.
    Lastly comes the implementation. This is basically the code inside a function. It is not necessary to be associated with an identifier. The compiler can generate code to call a function without knowing what it contains or does. But you do, of course, have to tell the compiler at some point what the function contains. How else can it generate the appropriate code for the program?

    Examples of declarations are function prototypes. They are enough for a compiler to call a function.
    An example of a definition is a struct or class. You can just type "class myclass;", but when you use the class, the compiler must know what this type is. So the whole information about the contents of the class is the definition. And finally, the code inside any of the class's functions are the implementation.

    Sometimes, declarations, definitions and implementations can be combined. Examples are when you're creating your struct. You don't have to type "struct mystruct;" first. Another example is a function, like menu above. It is a declaration and an implementation. When you create a variable, you are declaring and defining it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21