I am trying to port an application to win-dows (ironic, I know). The following bare-bone example illustrates the problem. I get the following error when compiling with VS12 and VS14:
C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::chrono::time_point<std::chrono::system_clock,std::chrono::system_clock::duration>' (or there is no acceptable conversion)
No errors on Ubuntu with g++. What am I missing?
logger.h
#pragma once
#include "stdafx.h"
#include <chrono>
#include <ostream>
std::ostream& operator<<(std::ostream &out, const std::chrono::time_point<std::chrono::system_clock> &time_point);
namespace Logging
{
inline std::chrono::time_point<std::chrono::system_clock> timestamp()
{
std::chrono::time_point<std::chrono::system_clock> time_point = std::chrono::system_clock::now();
return time_point;
}
class Event
{
public:
Event() : time_point(timestamp())
{
}
typedef std::unique_ptr< Event > Ptr;
friend std::ostream& operator<<(std::ostream &out, const Ptr &p)
{
out << p->time_point << "\t"; // << LINE CAUSING ERROR
return out;
}
private:
const std::chrono::time_point<std::chrono::system_clock> time_point;
};
}
logger.cpp
#include "stdafx.h"
#include <memory>
#include <ctime>
#include "logger.h"
std::ostream& operator<<(std::ostream &out, const std::chrono::time_point<std::chrono::system_clock> &time_point)
{
std::time_t time = std::chrono::system_clock::to_time_t(time_point);
struct tm t;
localtime_s(&t, &time); //localtime(&time) on linux
char buf[30];
int ret = ::strftime(buf, 30, "%Y/%m/%d %T", &t);
out << buf;
return out;
}
commands and flags
linux:
g++ -std=c++11 -Wall logger.cpp app.cpp -o app
windows:
/Yu"stdafx.h" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\chron_test.pch"