【发布时间】:2013-10-04 04:25:23
【问题描述】:
我正在尝试使用 SFML 创建线程应用程序,但在创建线程时遇到了这个错误。
error C2064: term does not evaluate to a function taking 1 arguments
这是我的代码,它的主要作用是设置网络监听和接受,我想要实现的是一个可以通过main 运行的网络线程。
#include "Networking.h"
Networking::Networking(void)
{
sf::Thread thread(&Networking::TCPSocket, 1000);
thread.launch();
}
Networking::~Networking(void)
{
SetNetworking(false);
}
void Networking::TCPSocket(int port)
{
InitNetworking();
sf::TcpSocket client;
sf::TcpListener listener;
// bind the listener to a port
if (listener.listen(port) != sf::Socket::Done)
{
Logger::Wrn("Could not bind to port:", port);
} else {
Logger::Log("Successfully bound to port:", port);
}
Logger::Log("Ready to receive connections");
while(IsNeworkRunning() == true)
{
if(listener.accept(client) == sf::Socket::Done)
{
Logger::Log("New connection received from");
} else {
Logger::Wrn("Connection from", client.getRemoteAddress(), "could not connect");
}
}
}
void Networking::SetNetworking(bool i)
{
i = this->_networkStarted;
}
bool Networking::IsNeworkRunning()
{
if(_networkStarted == false)
{
Logger::Err("Failed to initialise the networking");
exit(EXIT_FAILURE);
} else {
return _networkStarted;
}
}
void Networking::InitNetworking()
{
SetNetworking(true);
Logger::Log("Network initialised");
}
如果您需要标头,我可以发布它,但我不确定您是否会发布。
提前感谢您的帮助。
【问题讨论】:
-
当调用一个指向成员函数的指针时,你也需要一个指向将要调用它的对象的指针。
-
但是如果我这样做,那么我如何添加函数参数
-
传入绑定函数,通过
std::bind或类似方法创建。
标签: c++ multithreading sfml