undefined error

This is a discussion on undefined error within the Game Programming forums, part of the General Programming Boards category; i get keeping this error, undefined reference to Attack,Run and Defend. here is my code. Code: string battleSelect; void Battle(); ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    25

    undefined error

    i get keeping this error, undefined reference to Attack,Run and Defend. here is my code.

    Code:
    string battleSelect;
        void Battle(); {
             cout << "You Have engaged into battle!! What will you do?";
             cout << "\n[A]ttack, [R]un, [D]efend :";
             if (battleSelect == "a" || battleSelect == "A") {
                Attack(); }
             if (battleSelect == "r" || battleSelect == "R") {
                Run(); }
             if (battleSelect == "d" || battleSelect == "D") {
                Defend(); }
              }
    
    system("PAUSE");
    
             void Attack(); {
    
             };
    
             void Run(); {
    
             };
    
             void Defend(); {
    
             };
    
    
    
    
    
    
    
    
      return 0;
    }
    also, when i compile, I dont get a EXE file. and I cant run the text game. any ideas? also if any one can help me with a any of this i would be greatful. thank you all

  2. #2
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    You need to prototype or define the functions prior to calling them.
    To code is divine

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    You cant define functions inside other functions. What you have there is not C or C++ it is just a jumbled mess of nothing. Is that all your code?

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Try something along these lines:
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    void Battle(char);
    void Run();
    void Attack();
    void Defend();
    int main()
    {
    char battleSelect;
    Battle(battleSelect);    
    system("PAUSE");
    return 0;
    }
    void Battle(char bS) 
             {
             cout << "You Have engaged into battle!! What will you do?";
             cout << "\n[A]ttack, [R]un, [D]efend :";
             cin>>bS;
             if (bS == 'a' || bS == 'A')
                Attack();
             if (bS == 'r' || bS == 'R')
                Run();
             if (bS == 'd' || bS == 'D')
                Defend();
              }
    void Defend()
    {
    cout<<"Defending...\n";
    }
    void Attack()
    {
    cout<<"Attacking...\n";
    }
    void Run()
    {
    cout<<"Running...\n";
    }
    Last edited by jmd15; 09-30-2005 at 09:41 PM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    25
    no that isnt all my code. I didnt seem the need to post the hole thing thats all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM

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