Proof: Call a function with missing parameters doesn't work in C++
The snippet can be accessed without any authentication.
Authored by
Martin Wölzer
Edited
//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
Please register or sign in to comment