小编Dai*_*vys的帖子

Boost :: asio winsock和winsock 2兼容性问题

我的项目使用的是使用winsock.h的windows.h,我需要包含使用winsock2的boost:assio.所以我收到很多错误,说Winsock.h已经包含在内了.我可以定义WIN32_LEAN_AND_MEAN.所以windows.h不会使用winsock.问题是,我需要windows.h来使用它,我只需要Asio用于异步定时器.我不需要winsock2.h.我试着搜索如何禁用其winsock2使用,我发现我可以通过在包含boost:asio之前定义BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN来做到这一点,但我仍然得到相同的错误.

#include <windows.h>
#define BOOST_ASIO_NO_WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>
Run Code Online (Sandbox Code Playgroud)

错误

1> c:\ program files\boost\boost_1_47\boost\asio\detail\socket_types.hpp(22):致命错误C1189:#error:WinSock.h已包含在内

c++ winsock boost-asio winsock2 c-preprocessor

17
推荐指数
3
解决办法
3万
查看次数

Boost:Asio的游戏服务器如何异步工作?

我正在尝试创建一个游戏服务器,目前,我正在使用线程.每个对象(玩家,怪物)都有自己的线程与while(1)循环,执行特定的功能.

服务器基本上是这样的:

main(){

//some initialization

while(1)
{
//reads clients packet
//directs packet info to a particular object
//object performs some functions
//then server returns result packet back to client
Sleep(1);
}
Run Code Online (Sandbox Code Playgroud)

我听说使用这样的线程使服务器效率不高,我应该考虑使用Boost :: Asio,并使函数异步工作.但我不知道服务器如何工作.如果有人能解释这些服务器的工作原理,我将不胜感激.

multithreading boost boost-asio

4
推荐指数
1
解决办法
3652
查看次数

如何用参数写lambda函数?C++

我想用lambda函数调用一个方法(对于这个例子std :: thread构造函数),传递int值:

int a=10;

std::thread _testThread = thread([a](int _a){
  //do stuff using a or _a ?
});
_testThread.detach();
Run Code Online (Sandbox Code Playgroud)

我不知道如何正确编写这样的函数,我得到这个错误:C2064:term不计算为0参数的函数

c++ argument-passing inline-functions stdthread

2
推荐指数
1
解决办法
8928
查看次数

错误C2064:term不计算为取0参数的函数thread.hpp(60)

我正在创建c ++游戏服务器.服务器创建了许多对象monster,每个对象都monster应该具有特定功能的线程.

我收到错误:

 error C2064: term does not evaluate to a function taking 0 arguments
 thread.hpp(60) : while compiling class template member function 'void  
  boost::detail::thread_data<F>::run(void)'
Run Code Online (Sandbox Code Playgroud)

monster.cpp:

#include "monster.h"

monster::monster(string temp_mob_name)
{
    //New login monster
    mob_name = temp_mob_name;
    x=rand() % 1000;
    y=rand() % 1000;

        boost::thread make_thread(&monster::mob_engine);
} 

monster::~monster()
{
    //Destructor
}

void monster::mob_engine()
{
    while(true)
    {
         Sleep(100);
         cout<< "Monster name"<<mob_name<<endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

monster.h:

#ifndef _H_MONSTER_
#define _H_MONSTER_

//Additional include dependancies
#include <iostream>
#include <string>
#include …
Run Code Online (Sandbox Code Playgroud)

multithreading boost class object

1
推荐指数
1
解决办法
3112
查看次数

如何定义sqlite3 struct的静态指针?C++

我想要有sqlite3结构的静态指针,所以我可以打开一次连接到DB,在运行时执行一些查询并在程序出口关闭数据库连接.

(我链接了sqlite3 static lib,dll)

所以在我的班级标题中:

foo.h中:

#include "sqlite/sqlite3.h"

class foo
{
    public:
       static sqlite3 *db;
       static void connect();
}
Run Code Online (Sandbox Code Playgroud)

Foo.cpp中:

#include "foo.h"

sqlite3 foo::*db = nullptr;

foo::connect(){

   //sqlite3 *db;   //<-this works
   char *zErrMsg = 0;
   int rc;

   rc = sqlite3_open("test.db", &db);

   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      exit(0);
   }else{
      fprintf(stderr, "Opened database successfully\n");
   }
   //sqlite3_close(db); // close connection when program is exiting. Not here.

}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:LNK2001:未解析的外部符号"public static struct sqlite3*foo :: db"....

c++ sqlite static pointers unresolved-external

1
推荐指数
1
解决办法
281
查看次数