Just started using Boost. Socket only right now. Created one small class but cannot compile. Please help. Compile error is In file included from Server.cpp:8: ./include/Server.h:26: error: ‘io_service’ is not a type ./include/Server.h:26: error: expected unqualified-id before ‘(’ token ./include/Server.h:26: error: expected `)' before ‘(’ token ./include/Server.h:26: error: expected ‘,’ or ‘...’ before ‘(’ token ./include/Server.h:26: error: expected ‘;’ before ‘)’ token ./include/Server.h:27: error: ‘io_service’ is not a type ----- My header file: /* * Server.h * * Created on: Dec 1, 2008 * Author: */ #ifndef SERVER_H_ #define SERVER_H_ #include <boost/asio.hpp> class Server{ public: Server(){}; ~Server(){}; void print(); protected: private: boost::asio::io_service io_service; boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13)); boost::asio::ip::tcp::socket asio_socket(io_service); boost::system::error_code error_read; }; #endif /* SERVER_H_ */ ----- My cpp file: /* * Server.cpp * * Created on: Dec 1, 2008 * Author: */ #include "Server.h" void Server::print(){ }
AMDG James Peng wrote:
class Server{
public: Server(){}; ~Server(){};
void print(); protected:
private:
boost::asio::io_service io_service; boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13)); boost::asio::ip::tcp::socket asio_socket(io_service); boost::system::error_code error_read;
};
You can't initialize members in the class body. In Christ, Steven Watanabe
Steven Watanabe-4 wrote:
AMDG
James Peng wrote:
class Server{
public: Server(){}; ~Server(){};
void print(); protected:
private:
boost::asio::io_service io_service; boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13)); boost::asio::ip::tcp::socket asio_socket(io_service); boost::system::error_code error_read;
};
You can't initialize members in the class body.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I think I did this with ACE and other library. Boost is special? So I should use pointer? -- View this message in context: http://www.nabble.com/new-user-got-compile-error-tp20781541p20781826.html Sent from the Boost - Users mailing list archive at Nabble.com.
boost001 wrote:
Steven Watanabe-4 wrote:
AMDG
James Peng wrote:
class Server{
public: Server(){}; ~Server(){};
void print(); protected:
private:
boost::asio::io_service io_service; boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13)); boost::asio::ip::tcp::socket asio_socket(io_service); boost::system::error_code error_read;
}; You can't initialize members in the class body.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I think I did this with ACE and other library. Boost is special? So I should use pointer?
No, Boost isn't special. C++ doesn't allow you to initialize members in the class body. You need to use the constructor's initialization list like so: Server::Server() : acceptor( io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13) ) , asio_socket( io_service ) { }
participants (4)
-
boost001
-
James Peng
-
Kenny Riddile
-
Steven Watanabe