0

I'm writing a simple complex number C++ implementation as practice for overloading operators. One of the operators I simply cannot get past is <<. I get an undefined reference error to it whenever I try to call it. Here is a gist link to my code. I am compiling it with the following:

g++ -std=c++11 main.cpp complex.cpp -Wall -Wextra -o complex

In addition to the unused parameter warning in main(), I get the following:

/tmp/cc7qVwEF.o: In function `main':
main.cpp:(.text+0x1c5): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& rob::operator<< <char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, rob::Complex const&)'
collect2: error: ld returned 1 exit status
robbie
  • 1,219
  • 1
  • 11
  • 25
  • _unused parameter_ is _typically_ a warning, not an error. Please provide [mcve]. Most likely you didn't provide a definition for your operator overload. – Algirdas Preidžius Jul 05 '17 at 14:33
  • @AlgirdasPreidžius Whoops, sorry! I did mean warning. Also, if you check the code, I did provide a definition. – robbie Jul 05 '17 at 14:34
  • There is no [mcve] in the question. All the relevant code should be present in the question itself, and not in external links. – Algirdas Preidžius Jul 05 '17 at 14:35
  • Templated functions and methods can't be compiled separately. Move the definition of `operator<<` into the header file. – jodag Jul 05 '17 at 14:39

0 Answers0