fork download
  1. richard@richard-VirtualBox:~/Programming$ cat main.cpp
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. int getInteger();
  7.  
  8. int x { getInteger() };
  9. int y { getInteger() };
  10.  
  11. std::cout << x << " + " << y << " is " << x + y << '\n';
  12. return 0;
  13. }
  14. richard@richard-VirtualBox:~/Programming$ cat input.cpp
  15. #include <iostream>
  16.  
  17. int getInteger()
  18. {
  19. std::cout << "Enter an integer: ";
  20. int x{};
  21. std::cin >> x;
  22. return x;
  23. }
  24. richard@richard-VirtualBox:~/Programming$ g++ main.cpp -o main.o
  25. main.cpp: In function ‘int main()’:
  26. main.cpp:5:19: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  27. 5 | int getInteger();
  28. | ^~
  29. main.cpp:5:19: note: remove parentheses to default-initialize a variable
  30. 5 | int getInteger();
  31. | ^~
  32. | --
  33. main.cpp:5:19: note: or replace parentheses with braces to value-initialize a variable
  34. /usr/bin/ld: /tmp/ccRNaSLq.o: in function `main':
  35. main.cpp:(.text+0xd): undefined reference to `getInteger()'
  36. /usr/bin/ld: main.cpp:(.text+0x15): undefined reference to `getInteger()'
  37. collect2: error: ld returned 1 exit status
  38. richard@richard-VirtualBox:~/Programming$
  39.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty