C++:MSVC 仅使用 Boost::asio 检测到语法错误
C++: syntax error detected by MSVC only using Boost::asio
我正在使用 Boost::ASIO.
在 C++ 中制作基本的客户端-服务器架构
MSVC 在此行报告 syntax error: '.'
(C2059):
void
Server::start()
{
m_stopped = false;
listen_one();
m_runner = std::make_unique<std::thread>([this](){
io_service.run(); // <- syntax error: '.'
});
m_runner->detach();
}
- GCC 和 Clang 都可以在 Linux 和 macOS 上编译相同的代码。
- 改了几次代码,编译了几次,还是报错
- 还有另一个代码块,MSVC 没有检测为错误:
void
Client::init()
{
m_socket->connect(boost::asio::ip::tcp::endpoint(
boost::asio::ip::address::from_string(m_ip),
static_cast<short unsigned int>(m_port)));
Connection::init();
m_runner = std::make_unique<std::thread>([this](){
io_service.run(); // <- this line is fine
});
m_runner->detach();
}
基本调试:
io_service
、m_stopped
、m_runner
是Server的成员变量,listen_one()
是成员函数。
- 服务器没有继承任何东西。 (如果相关,Client继承另一个class,Connection)
为什么 MSVC 检测到语法错误,而 GCC 和 Clang 都检测不到?
Can you try this->io_service.run()?
MSVC 长期以来一直受到两阶段查找的挑战。
- What exactly is "broken" with Microsoft Visual C++'s two-phase template instantiation?
- http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html
- Two-phase name lookup support comes to MSVC (2017)
也许就是这样。 this->
明确表示 io_service
代表 class 成员。在显示的 lambda 中,它通常不重要(除非 class 实际上被声明为模板的一部分?)。
另一个起作用的因素可能是名称隐藏:io_service
隐藏了类型的名称。如果该类型名称在没有命名空间限定的情况下可见,则可能会导致 MSVC 混淆。
我正在使用 Boost::ASIO.
在 C++ 中制作基本的客户端-服务器架构MSVC 在此行报告 syntax error: '.'
(C2059):
void
Server::start()
{
m_stopped = false;
listen_one();
m_runner = std::make_unique<std::thread>([this](){
io_service.run(); // <- syntax error: '.'
});
m_runner->detach();
}
- GCC 和 Clang 都可以在 Linux 和 macOS 上编译相同的代码。
- 改了几次代码,编译了几次,还是报错
- 还有另一个代码块,MSVC 没有检测为错误:
void
Client::init()
{
m_socket->connect(boost::asio::ip::tcp::endpoint(
boost::asio::ip::address::from_string(m_ip),
static_cast<short unsigned int>(m_port)));
Connection::init();
m_runner = std::make_unique<std::thread>([this](){
io_service.run(); // <- this line is fine
});
m_runner->detach();
}
基本调试:
io_service
、m_stopped
、m_runner
是Server的成员变量,listen_one()
是成员函数。- 服务器没有继承任何东西。 (如果相关,Client继承另一个class,Connection)
为什么 MSVC 检测到语法错误,而 GCC 和 Clang 都检测不到?
Can you try this->io_service.run()?
MSVC 长期以来一直受到两阶段查找的挑战。
- What exactly is "broken" with Microsoft Visual C++'s two-phase template instantiation?
- http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html
- Two-phase name lookup support comes to MSVC (2017)
也许就是这样。 this->
明确表示 io_service
代表 class 成员。在显示的 lambda 中,它通常不重要(除非 class 实际上被声明为模板的一部分?)。
另一个起作用的因素可能是名称隐藏:io_service
隐藏了类型的名称。如果该类型名称在没有命名空间限定的情况下可见,则可能会导致 MSVC 混淆。