c++ - Strange compilation errors in boost buffer_sequence_adapter -


i'm writing code connect instrument using serial connection , send commands. here's code far:

#include <boost/asio/basic_serial_port.hpp> #include <iostream> #include <iterator> #include <algorithm>   #define port "com3" #define baud 9600 #define databits 8 #define parity none #define stop_bits 1 #define flow_control none  int main() {     using namespace boost;      //create serial connection scope     asio::io_service io;     asio::basic_serial_port<asio::serial_port_service> scope(io);      //open connection , configure     scope.open(port);     scope.set_option(asio::serial_port_base::baud_rate(baud));     scope.set_option(asio::serial_port_base::flow_control(asio::serial_port_base::flow_control::flow_control));     scope.set_option(asio::serial_port_base::parity(asio::serial_port_base::parity::parity));     scope.set_option(asio::serial_port_base::stop_bits(asio::serial_port_base::stop_bits::stop_bits));     scope.set_option(asio::serial_port_base::character_size(databits));      //open connection      //send test commands     scope.write_some("move x y \n");      //close port     scope.close();      return 0; } 

it looks fine in visual studio when compiled gives me 16 errors, in boost's buffer_sequence_adapter.hpp in first section. library code of course looks fine, i'm not sure why won't compile. of errors follows:

error   1   error c2825: 'buffers': must class or namespace when followed '::'  c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   2   error c2039: 'const_iterator' : not member of '`global namespace'' c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   3   error c2146: syntax error : missing ';' before identifier 'iter'    c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   4   error c2734: 'const_iterator' : const object must initialized if not extern  c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   5   error c2065: 'iter' : undeclared identifier c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   6   error c2228: left of '.begin' must have class/struct/union  c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 156 1   consoleapplication1 error   7   error c2825: 'buffers': must class or namespace when followed '::'  c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 157 1   consoleapplication1 error   8   error c2039: 'const_iterator' : not member of '`global namespace'' c:\program files\boost_1_55_0\boost\asio\detail\buffer_sequence_adapter.hpp 157 1   consoleapplication1 

any appreciated!

you need wrap literal tell asio how want buffer interpreted, e.g.

scope.write_some(boost::asio::buffer("move x y \n")); 

note, in way buffer includes trailing nul character well. if wanted avoid this, could

const char* message = "move x y \n"; scope.write_some(boost::asio::buffer(message, strlen(message))); 

background: reason "it looks okay in vs" (by mean intellisense didn't diagnose error before compilation) because (at least several overloads of) write_some function templates, , intellisense doesn't try instantiate templates specific parameter.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -