日志向。。记录一下迁移中遇到的几个不那么明显的编译错误。。都是由于c++11标准更加严格,以前编译器帮忙做的事现在不让做了导致的。对c++11标准没有去研究(md基础的c++都没学好呢TAT),所以只记录问题和目前的解决方法,到底为什么这么改或者有没有更好的修改方法以后学习过了再说。
1.std::basic_istream中会用到ctype<_CharT>,而ctype<_CharT>只有char和wchar两种实现。如果basic_istream中传进来的模板参数是boost::uint8_t的话不会做类型转换而直接报错。之前应该是编译器会自动做类型转换?
2.定义在类中的友元模板参数需要先声明才能被同一命名空间的其他类所调用。
例子:
class SubPieceContentImp
{
public:
typedef boost::intrusive_ptr<SubPieceContentImp> pointer;
template <typename T>
friend T buffer_static_cast(
SubPieceContentImp<size> & buf)
{
return static_cast<T>(buf.buffer_);
}
};
template <boost::uint32_t size>
class SubPieceContentImp;
template <typename T, boost::uint32_t size>
T buffer_static_cast(SubPieceContentImp<size> & buf);
class A{
<span style="white-space:pre"> </span>struct PEER_RECVTIME
{
PEER_RECVTIME(boost::uint32_t recv_time_, ConnectionBasePointer peer_)
: recv_time(recv_time_), peer(peer_) {}
PEER_RECVTIME(const PEER_RECVTIME & p1)
: recv_time(p1.recv_time), peer(p1.peer){}
boost::uint32_t recv_time;
ConnectionBasePointer peer;
};
<span style="white-space:pre"> friend inline bool operator < (PEER_RECVTIME & p1, PEER_RECVTIME & p2);</span>
};
<span style="white-space:pre"> inline bool operator < (Assigner::PEER_RECVTIME & p1, Assigner::PEER_RECVTIME & p2)
{
return p1.recv_time < p2.recv_time;
}</span>
class A{
struct PEER_RECVTIME
{
PEER_RECVTIME(boost::uint32_t recv_time_, ConnectionBasePointer peer_)
: recv_time(recv_time_), peer(peer_) {}
PEER_RECVTIME(const PEER_RECVTIME & p1)
: recv_time(p1.recv_time), peer(p1.peer){}
boost::uint32_t recv_time;
ConnectionBasePointer peer;
bool operator < (const PEER_RECVTIME & p) const
{
return recv_time < p.recv_time;
}
};
};