Thread: undefined reference(new standards have me lost)

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    3

    undefined reference(new standards have me lost)

    I have been messing around with C++ for awhile but in a class room setting and apparently the things that they are doing there are VERY WRONG!!
    The code I have is simple, but I get [Linker error]undefined reference to Selection(char) when I compile.

    Code:
      #import <iostream>
      #import "guitar.h"
    
      using namespace std;
    
      //function prototypes
      char Selection(char choice);
      int ESection();
    
      int main()
      {
        //declare variables
        char choice;
        
        cout<<"\n\n";    //print 2 blank lines
        cout<<head << "\n\n" << head2;
        choice = Selection(choice);
        system("PAUSE");
      }
    my header:
    Code:
      using namespace std;
    
      char Selection()
      {
        //declare variables
        char select;
        //This function display a list of choices to the user
        cout<<"Please select a category: \n\n";
        cout<<"E Section                 A#/Bb Section\n";
        cout<<"F Section                 B Section\n";
        cout<<"F#/Gb Section         C Section\n";
        cout<<"G Section                 C#/DB Section\n";
        cout<<"G#/Ab Section         D Section\n";
        cout<<"A Section                 D#/Eb Section\n";
        cout<<"Enter: ";
        cin.get(select);
        return select;
      }
    A kick in the right direction would be great. I read posts here and googled it but I am still unsure of what the solution is.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    1. Take that function out of the header file and put it in either *.cpp file. The Selection in the header file is not the same as prototyped in the *.cpp file -- look at the parameter differences.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    3
    STUPID mistake!!!!

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Also the prototype declaration: char Selection(char choice); goes in the *.h
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM