Global function definition in header file - how to avoid duplicated symbol linkage error

后端 未结 4 1396
执念已碎
执念已碎 2020-11-29 11:41

I have the following code in a header only file.

#pragma once

class error_code {
public:
    unsigned __int64 hi;
    unsigned __int64 lo;    
};

std::ostr         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 11:51

    Use the inline keyword.

    inline std::ostream& operator<< (std::ostream& o, const error_code& e) {
        return o << "[" << e.hi << "," << e.lo << "]";
    }
    

提交回复
热议问题