Skip to content
Snippets Groups Projects

Proof: Call a function with missing parameters doesn't work in C++

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Martin Wölzer
    Edited
    example.cpp 418 B
    //file lib.cpp:
    #include<cstdio>
    void test(int a, int b) {
        printf("%d, %d\n", a, b);
    }
    
    //file main.cpp:
    void test(int a); 
    int main() {
        test(128);
    }
    
    //compile with `g++ -c -o lib.o lib.cpp; g++ lib.o main.cpp -o main`
    //gives the following error:
    //  /usr/bin/ld: /tmp/ccRGbh1g.o: in function `main':
    //  main.cpp:(.text+0xa): undefined reference to `test(int)'
    //  collect2: error: ld returned 1 exit status
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment