class Connection
{
public:
explicit Connection(boost::asio::io_service& io_service);
virtual ~Connection();
boost::asio::ip::tcp::socket& socket();
virtual void OnConnected()=0;
void Send(uint8_t* buffer, int length);
bool Receive();
private:
void handler(const boost::system::error_code& error, std::size_t bytes_transferred);
boost::asio::ip::tcp::socket socket_;
};
-----------------------------------------------------------------------------------
Server::Server(boost::asio::io_service& io_service,short port)
: acceptor_(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)){
m_connections = new std::vector<Connection*>();
start_accept();
std::cout<<"Socket accepting connections..."<<std::endl;
}
Server::~Server()
{
m_connections->clear();
delete m_connections;
}
void Server::start_accept(){
/* Connection::pointer new_connection =
Connection::create(acceptor_.io_service());*/
acceptor_.async_accept(m_connections->front()->socket(),
boost::bind(&Server::handle_accept, this, m_connections,
boost::asio::placeholders::error));
}
它構建沒有錯誤的項目,但是當我試圖運行它的中斷程序,並給了我這個錯誤矢量:0000005:在AccountServer.exe 0x00066314未處理的異常訪問衝突讀取位置0xccccccd0
Unhandled exception at 0x00066314 in AccountServer.exe: 0xC0000005: Access violation reading location 0xccccccd0.
這裏有什麼問題?
您是否嘗試過調試器?事故究竟發生在哪裏? – 2011-05-23 11:58:15
@ Space_C0wb0y是的,它說'矢量迭代器不dereferencabel' – Abanoub 2011-05-23 12:14:57