2016-11-30 60 views
-2

我如何正確重寫下一個源代碼?它是GLib驅動的IRC-bot的一部分。編譯器崩潰,並顯示下一個錯誤:爲什麼下一個代碼不能編譯?

src/irc.cpp:20:9: error: cannot call member function ‘Glib::ListHandle<Glib::RefPtr<Gio::InetAddress> > Gio::Resolver::lookup_by_name(const Glib::ustring&, const Glib::RefPtr<Gio::Cancellable>&)’ without object 
    ), 

來源:

#include "includes.hpp" // Just including all the files 

Glib::RefPtr<Gio::Socket> ircSock; // Our socket 

void ircInit() { // Init-function 
    try { 
    ircSock = Gio::Socket::create(// Creating socket 
     Gio::SocketFamily::SOCKET_FAMILY_IPV4, 
     Gio::SocketType::SOCKET_TYPE_STREAM, 
     Gio::SocketProtocol::SOCKET_PROTOCOL_TCP 
    ); 

    ircSock->connect(// Problematic code 
     Gio::InetSocketAddress::create(
     Gio::Resolver::lookup_by_name(
      "irc.freenode.net", // For-example 
      Gio::Cancellable::create() 
     ), 
     6667 
    ), 
     Gio::Cancellable::create() 
    ); 
    } catch(const Glib::Error& e) { 
    std::cerr << "IRC: Error: " << e.what() << std::endl; // Error-reporting 
    } 
} 
+5

因爲它是一個成員函數。你不能把它稱爲靜態函數。 –

回答

3

根據documentation,這是成員函數,因此,你需要構造對象調用它,而你正在嘗試調用它像它是靜態功能。

正確的修復方法是創建Gio::Resolver對象,並在創建的對象上調用此方法。

+0

好的,我會試試。 – Ancient

+0

'src/irc.cpp:19:18:error:請求'resolver'中的成員'lookup_by_name',它是非類類型的'Gio :: Resolver()'(對不起,我是C++新手。當前版本:[這裏](http://hastebin.com/sasezeroju.php) – Ancient