Like Tree2Likes
  • 2 Post By Salem

undefined reference

This is a discussion on undefined reference within the C++ Programming forums, part of the General Programming Boards category; The problem with the code is on line 14 and says undefined reference to `push(int) Code: #include<iostream> using namespace std; ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    7

    undefined reference

    The problem with the code is on line 14 and says undefined reference to `push(int)

    Code:
    #include<iostream>
    using namespace std;
    void push(int n);
    int pop(int &n);
    struct elem{
           int key;
           elem *next;
           }*first=NULL,*last=NULL,*p;
    
    int main()
    {int n;
    cout<<"n=";
    while(cin>>n)
    push(n);
    while(pop(n))
    cout<<n<<"";
    }
    
    void push(int n,int key)
    {p=last;
    last=new elem;
    last->key=n;
    last->next=NULL;
    if(p!=NULL)
    p->next=last;
    if(first==NULL)
    last=first;
    }
    
    int pop(int &n)
    {if(first)
    {n=first->key;
    p=first;
    first=first->next;
    if(first==NULL)
    last=first;
    delete p;
    return 1;
    }
    else return 0;}

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    1. Your indentation is rubbish -> SourceForge.net: Indentation - cpwiki

    2. Spot the difference.
    void push(int n);
    ...
    push(n);
    ...
    void push(int n,int key)
    stahta01 and dwks like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    111
    In other words you are trying to use a function that you have not defined.
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined reference to ...
    By ArgentSun in forum C Programming
    Replies: 16
    Last Post: 01-28-2011, 01:27 PM
  2. Undefined reference ?
    By Holymanus in forum C Programming
    Replies: 6
    Last Post: 01-07-2011, 08:15 AM
  3. undefined reference to
    By diego in forum C++ Programming
    Replies: 4
    Last Post: 05-18-2010, 03:06 PM
  4. Undefined Reference to...
    By JJFMJR in forum C++ Programming
    Replies: 3
    Last Post: 08-16-2008, 03:09 AM
  5. Undefined Reference
    By Russell in forum C++ Programming
    Replies: 7
    Last Post: 06-02-2004, 02:08 AM

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