我从我的类中移出了方法实现并捕获了以下错误:
use of class template requires template argument list
Run Code Online (Sandbox Code Playgroud)
对于方法whitch根本不需要模板类型...(对于其他方法都可以)
类
template<class T>
class MutableQueue
{
public:
bool empty() const;
const T& front() const;
void push(const T& element);
T pop();
private:
queue<T> queue;
mutable boost::mutex mutex;
boost::condition condition;
};
Run Code Online (Sandbox Code Playgroud)
错误的实施
template<> //template<class T> also incorrect
bool MutableQueue::empty() const
{
scoped_lock lock(mutex);
return queue.empty();
}
Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用boost.我正在使用异步套接字编写TCP客户端服务器.
任务如下:
现在工作如下
如何允许客户端从键盘输入数字并同时等待服务器的回答?
为什么我的客户不等待服务器的答案?
客户端代码:
using boost::asio::ip::tcp;
class TCPClient
{
public:
TCPClient(boost::asio::io_service& IO_Service, tcp::resolver::iterator EndPointIter);
void Close();
private:
boost::asio::io_service& m_IOService;
tcp::socket m_Socket;
string m_SendBuffer;
static const size_t m_BufLen = 100;
char m_RecieveBuffer[m_BufLen*2];
void OnConnect(const boost::system::error_code& ErrorCode, tcp::resolver::iterator EndPointIter);
void OnReceive(const boost::system::error_code& ErrorCode);
void OnSend(const boost::system::error_code& ErrorCode);
void DoClose();
};
TCPClient::TCPClient(boost::asio::io_service& IO_Service, tcp::resolver::iterator EndPointIter)
: m_IOService(IO_Service), m_Socket(IO_Service), m_SendBuffer("")
{
tcp::endpoint EndPoint = *EndPointIter;
m_Socket.async_connect(EndPoint,
boost::bind(&TCPClient::OnConnect, this, boost::asio::placeholders::error, ++EndPointIter));
}
void TCPClient::Close()
{
m_IOService.post( …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Linux上编译单元测试(boost),但编译器发生了错误.有人可以查看我的命令吗?
g++ -o UTest ../UTest/UT1.cpp ../UTest/UT2.cpp -lboost_system -lboost_thread -lboost_unit_test_framework
Run Code Online (Sandbox Code Playgroud)
错误
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
Run Code Online (Sandbox Code Playgroud)
我main()从g ++命令中删除了因为它在使用时不应该boost unit test使用.
怎么了?
PS没有单元测试(带main())的项目编译得很好.Windows上的单元测试工作正常.
更新
问题main()已解决.但是一个新的诞生了.
双方UT1.cpp并UT2.cpp已列入UTCommon.h,现在我有很多类似如下的错误
错误
tmp2.cpp:(.text+0xd44a): multiple definition of `boost::unit_test::unit_test_log_t::operator<<(boost::unit_test::lazy_ostream const&)'
/tmp/cc0jw8uR.o:tmp.cpp:(.text+0xd44a): first defined here
/tmp/cctLn9QJ.o: In function `boost::test_tools::tt_detail::equal_impl(char const*, char const*)'
Run Code Online (Sandbox Code Playgroud)
UTCommon.h
#ifndef UT_COMMON_H
#define UT_COMMON_H
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE UnitTest
#endif
#if defined (__GNUC__) && defined(__unix__)
#include <boost/test/included/unit_test.hpp>
#elif defined …Run Code Online (Sandbox Code Playgroud) 是否有标准的C/C++标头,其定义为byte,kilobyte,megabyte,......?我不想做自己的定义.在我看来这很脏.
例:
if (size > MEGABYTE)
{ ... }
Run Code Online (Sandbox Code Playgroud)