0

I'm getting the same linker error when trying to run code: ld.lld: error: undefined symbol: Serialize::Archive& Serialize::Archive::operator>><double>(double&)

main.cpp (snippets):

using namespace Serialize;
Archive arc(file, Archive::Save_Archive);
    
    double test;
    std::cout<<"Enter some data: ";
    std::cin >> test;
    arc >> test;

Archive.hpp:

namespace Serialize{
template<typename T>
    Archive& operator>>(T& obj); 
}

Archive.cpp:

namespace Serialize{
template<typename T>
    Archive& Archive::operator>>(T& obj){};
}

I don't believe I have any namespace issues and the operator is only defined and declared once in the hpp and cpp files.

I tried switching around using namespace Serialize and namespace Serialize and even just doing

Serialize::Archive arc(file, Serialize::Archive::Save_Archive);
  • 1
    @Nathan Heffington Move the definition of the template operator in the header. The compiler is unable to instantiate the operator when it compiles the module with main. – Vlad from Moscow Jul 28 '23 at 22:24
  • https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – pm100 Jul 28 '23 at 22:44

0 Answers0